Jump to content

johnmerlino

Members
  • Posts

    71
  • Joined

  • Last visited

    Never

Everything posted by johnmerlino

  1. Hey all, Let's say if all of the data in the site is the result of queries from the database that are output as html by php as users interact with the site. For example, there's no home.php file. Rather user clicks the link to view the page, and a php script pulls data from database and renders the page at that time. There is no javascript involved in this process. Would this page be crawlable by google? Thanks for response.
  2. So should I default all the value attributes to 1. Therefore, when the checkbox is checked, it will send that 1 to the php array?
  3. Hey all, THe problem I am having is even when I check the checbox, it still sends a value of 0 to the php array and hence nothing is ever updated: <input type="checkbox" name="approved[1]" value="1" checked="checked" /> <input type="checkbox" name="approved[3]" value="0" /> <input type="checkbox" name="approved[4]" value="0" /> So the second item is not checked by default. But even when I check it, my post array contains this: array(2) { [1]=> string(1) "1" [3]=> string(1) "0" } Notice the "0". It should be "1" now since I checked the second option. This is the function: function update(){ $vanity_url = new VanityUrl(); $checkbox = $this->input->post('approved'); //this is same thing as $_POST if(isset($checkbox)){ foreach($checkbox as $key => $value){ $vanity_url->where('id',$key)->get(); $vanity_url->approved = (int)$value; $vanity_url->save(); $vanity_url->check_last_query(); } } } That check_last_query() function outputs this: UPDATE `vanity_urls` SET `approved` = 1 WHERE `id` = 1 UPDATE `vanity_urls` SET `approved` = 0 WHERE `id` = 3 So despite checking the second option it still sets it to 0. Thanks for response.
  4. That won't work if the result is returning a function: $limit = isset($this->input->get('limit')) ? $this->input->get('limit') : 25;
  5. or do you mean: $results = "select * from vanity_urls order by approve asc"; foreach($result as $r) echo $r->url;
  6. @PFMaBiSmAd So you are saying create two variables: $approved = "select * from vanity_urls where approved=1"; $unapproved = "select * from vanity_urls where approved=0"; and then iterate through the variables? echo "approved:"; foreach($approved as $a) echo $a->url; echo "unapproved:"; foreach($unapproved as $u) echo $u->url; That is faster than storing them in arrays in php and iterating through the php arrays? Thanks for response.
  7. Hey all, I'm wondering the best way to use foreach to break a list of records into groups. For example, the problem with this: foreach($vanity_url as $v){ if($v->approved){ echo "Approved vanity urls:"; echo $v->url; } else { echo "Unapproved vanity urls:"; echo $v->url; } } is it will return this: Approved vanity urls: michellefrancis Unapproved vanity urls: johnmerlino Unapproved vanity urls: ericmayers when I want it to return this: Approved vanity urls: michellefrancis Unapproved vanity urls: johnmerlino ericmayers thanks for response
  8. Hey all, I think I get these two wrong: 'blogs/([a-zA-Z0-9\-_\/])' 'blogs/categories/([a-zA-Z0-9\-_\/])' I want the first to match something like blogs/johnmerlino but not blogs/ or not blogs/johnmerlino/abcdef I want the second to match something like blogs/categories/johnmerlino but not blogs/categories/ or blogs/ or blogs/categories/johnmerlino/abcdef Thanks for response.
  9. Hey all, I want to have an object that has a property which is an object containing instances of other objects. I try this: class Blog extends Posts { public $has_posts; public function __construct($a,$b,$c){ $has_posts = (object) array_merge((array) $a, (array) $b, (array) $c); } } class Posts { public $b; public function __construct($b){ $this->b = $b; } } $post1 = new Posts(1); $post2 = new Posts(2); $post3 = new Posts(3); $blog = new Blog($post1,$post2,$post3); var_dump($blog->has_posts); //null foreach($blog->has_posts as $post){ //Invalid argument supplied for foreach() echo $post->b; } But as you see, has_posts is null, not an object containing other objects. Thanks for response.
  10. Now this works fine: $str = "Welcome to the blog of " . $blogger->first_name . ' ' . $blogger->last_name; $str .= (!is_null($blogger->job_title)) ? ', ' . $blogger->job_title . '.' : '.'; echo $str; But why the need for string concatenation here? Why couldn't I stick ternary on the same line?
  11. Hey all, when job_title property is equal to null, I want this to happen: Welcome to the blog of John Merlino. If it is not null then: Welcome to the blog of John Merlino, a web designer. //where web designer refers to the value stored in job_title So I come up with this: echo "Welcome to the blog of " . $blogger->first_name . ' ' . $blogger->last_name . (!is_null($blogger->job_title)) ? ', ' . $blogger->job_title . '.' : '.'; But when job_title is null, all the page renders is this: , . That's right. Just a comma, then a space, and then a period. What am I missing here? Thanks for response.
  12. Hey all, When someone clicks a link, link looks like this: http://site/homes/edit/1?image=true Now on the same page, I have another link, which posts to the edit method as well, but no query string passed: http://site/homes/edit/1 I want to check if image key is set to true and basd on that, determine which view to render for the user, that is, whether to display the edit form to edit post or the image form to edit image. But by using the get array to try to grab query string: if($_GET["image"]=="true"){ I get the following error: Message: Undefined index: image It appears that $_GET is not successfully grabbing the parameter. Thanks for response.
  13. Hey all, I am building a simple cms. I have a posts table and I have an images table. A post has many images and images has a foreign key to the posts table. So when a user edits, updates, creates, and deletes a post, they affect the images related to the post. Sometimes a post can have more than one image, like three images. Hence I rendered this in the view (note that I am using a datamapper that converts tables to objects and fields to key/value pairs): foreach($records as $post){ echo form_open_multipart("homes/update/$post->id"); //File uploads require a multipart form. Default form handling uses the application/x-www-form-urlencoded content type. Multipart forms use the multipart/form-data encoding. //this is critical to pass the id as part of the action attribute of the form, so we can use our params hash to target the id to update the specific record echo label('Update Title'); echo form_input('title',$post->title); echo label('Update Body'); echo form_textarea('body',$post->body); $images = $post->images->include_join_fields()->get(); if(!is_null($images->image_file_name)){ echo label('Update Images'); foreach($images as $image){ echo form_upload('image_file_name',$image->image_file_name); } } } echo form_submit('submit','Update'); The above line of code will render a few input file types. The problem occurs during posting to my update method. It is looking for one parameter from the input file field and so if I upload three different images, it will only look for one and write only one to database: $field_name = 'image_file_name'; if ( ! $this->upload->do_upload($field_name)){ $error = array('error' => $this->upload->display_errors()); echo $error['error']; // redirect('homes/edit'); } else { $data = array('upload_data' => $this->upload->data()); $image_file_name = $data['upload_data']['file_name']; Is it possible to do wht I am trying to do? Should I only have on input file type per form submission or is that I need to fix the code to accomodate for multiple submissions by creating an array of sorts? Thanks for response.
  14. Hey all, I'm using mvc framework, where I use controllers for all my main views, such as home page, about us page, contact, etc. However, all the views contain something in common: the ability to create post, update post, delete post, edit post. So I use one model to handle this corresponding to one table called posts. This table contains all the content of the site. Now on different views, I want to render specific posts that relate to views. Currently my index method for all the controllers call the same find method: public static function find($param){ $self = get_instance(); if($param === '*' || $param === 'all'){ $resources = $self->db->get('posts'); //but I can't do self::db - because db is not a static property of the Home class, which is what self is pointing to. return $resources->result(); //result() returns the query result as an array of objects whereas result_array() returns the query result as a pure array. } return null; } With this find method, all of my views will render all of the posts. So I am wondering should I create another field in the database called page_id, which corresponds to a controller. So when the user invokes index method of home controller, I pass in an additional parameter like '1' and query the database to select all records where the page_id is equal to 1. Is this effective or is there a better approach to restrict posts that display in a content management system? Thanks for response.
  15. Hey all, Let's say I want to do something like this: <?php function exists($a){ $b ||= $a; } echo exists(1); ?> Basically, every time exists is called, it will only assign b to a if b isn't already initialized. What's the most effective way to achieve the equivalent in php? ternary? Thanks for response.
  16. I took care of the missing arguments issue. But now codeigniter tells me this: Indirect modification of overloaded property User::$_ci_scaffolding has no effect Filename: libraries/Model.php
  17. Hey all, Using codeigniter, I create a new user object and grab the user input (email and password) from a form: public function signup(){ $this->template->render_content('template', '/users/signup'); $user = new User($this->input->post('email'),$this->input->post('password')); if($_SERVER['REQUEST_METHOD'] == 'POST'){ if($user.save()){ redirect('/home/index', 'refresh'); } else{ redirect('/users/login', 'refresh'); } } } The constructor function of user model assigns the user input to this object: public function __construct($email,$password){ $this->email = $email; $this->password = $password; } By using the __get and __set magic method, this calls two setter methods: public function setEmail($email){ if ( ! is_null( $email ) ) { $this->_email = $email; } return null; } public function setPassword($password){ if ( ! is_null( $password ) ) { User::$password_salt = User::randomize(); User::$encrypted_password = User::encrypt($this->password,User::$password_salt); } return null; } I clearly pass two arguments when instantiating user. Yet I get this error message: Message: Missing argument 1 for User::__construct() Thanks for response. Can someone move this to the general help forum? I meant to submit it there. Thanks.
  18. Hey all, In my controller I have this: public function __construct(){ parent::Controller(); $this->load->model('home'); } public function index(){ $result = Home::find('all'); } In model this: public function __construct(){ parent::Model(); } public static function find($param){ if(is_null($param) || $param === 'all'){ $resources = $this->db->get('home'); //but I can't do self::db - because db is not a static property of the Home class, which is what self is pointing to. return $resources->result(); } return null; } } Since $this property is a reference to an object (a new instance), and a static method is not an instance, but a class method, I must use self and not this in the function block. However, the db property codeigniter provides cannot be called as a static property, since it was not declared as such. So when I get the error: Fatal error: Access to undeclared static property: Home::$db or Fatal error: Using $this when not in object context I am not sure what to do. Thanks for response.
  19. Hey all, I'm looking to produce a random 10 character string like: abcABC0123 when the below method is called: <?php function randomize(){ $chars = explode(' ',(range("a","z"))) . explode(' ',(range("A","Z"))) . explode(' ',(range("0","9"))); $pass = ""; for($i = 0; $i < $len; $i += 1){ array_push($pass,$chars[rand(count($chars)-1)]); } return $pass; } var_dump(randomize(10)); ?> But the randomize method is not returning desired result. Any idea what I'm doing wrong? Thanks for response.
  20. A developer spent over a month integrating WordPress MU with an existing php site. Basically, the task was to ensure that when the user logs into main site, they are already logged into blog. In other words, they don't need to log in twice. Also the admin should be the admin of main site, so the admin of main site has privilege to edit posts by users. There were a number of issues encountered while trying to integrate WordPress MU including database structure. Ultimately, I felt that all the time spent on this project, it would have been better time spent using a php framework like codeigniter and building the blog from scratch using this framework. It would have probably taking equal amount of time and been more robust. This blog would be important to site but it won't be the site (the site would have a lot of other custom PHP functionality developed from scratch), expecting thousands of visitors and therefore performance must be strong and bugs must be minimal. In the future, should I use a prebuilt blog tool such as WordPress MU or should I build blog from scratch on top of an mvc framework like codeignitor? The site has already been developed in PHP and future versions will be developed using codeigniter, so I will never build the whole thing on top of something like wordpress. I am just referring to the blog component, whether I should use existing blog software such as WordPress MU (or is there something better?) or build it from scratch and why should I choose one over the other. Thanks for response.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.