Welcome Guest, Not a member yet? Register   Sign In
  Re-mapping URI segments when using sub-folders in /controllers
Posted by: El Forum - 09-01-2007, 03:49 AM - No Replies

[eluser]Matthew Pennell[/eluser]
I'm using a sub-folder for my controllers, so I can do:

http://www.example.com/sub-folder/controller/method/id

However, this means that the id passed through above is in $this->uri->segment(4) instead of segment 3 where it normally would be.

Is there any way to either:

a) Re-map the URI segments so 4 is 3 and so on; or
b) Use the routes.php re-mapping rules to map requests onto controllers in sub-folders while retaining the correct numbering of URI segments?

Smile


  How to use get_instance in PHP5?
Posted by: El Forum - 09-01-2007, 03:36 AM - No Replies

[eluser]Optimus Prime[/eluser]
Hi! I'm practicing in CI programming. I have a question about get_instance and how use it in PHP5. I want to use hooks to to check the uri at the pre_controller level.

I used this in the hook.php

Code:
$hook['pre_controller'][] = array(
                                'class'    => 'Testhook',
                                'function' => 'test',
                                'filename' => 'testhook.php',
                                'filepath' => 'hooks',
                'params'   => array()
                                );
in testhook.php:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Testhook{

var $CI;
var $urisegment;

    function __construct()
    {
        $this->CI =& get_instance();
        $this->CI->load->helper('url');
        $this->urisegment = $this->CI->uri->segment(1);  //<< Only for test.
    }
    
    function test()
    {
        echo "Your uri in segment 1: ".$this->urisegment
    }
}

?&gt;
Suppose that to access to the welcoming message I type:

localhost/testsite/index.php

(all the site is contained in a folder called "testsite" and the C.I. folder is inside in "testsite")

But I get:
Code:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: hooks/Testhook.php
Line Number: 11

Fatal error: Call to a member function helper() on a non-object in /opt/lampp/htdocs/testsite/framework/application/hooks/testhook.php on line 11

What's wrong? I have read several posts about get_instance. Maybe I missed something about the get_instance. but I can't get it... I admit that i'm newbie with C.I. and advanced PHP5 Object Oriented Programming.

I'm using Fedora 7 with XAMPP to test this framework.

I will appreciate for your help.


  How can I get out of the manual and into the actual application?
Posted by: El Forum - 09-01-2007, 02:25 AM - No Replies

[eluser]Unknown[/eluser]
I've just installed CodeIgniter and read the manual (since it was the only link on the page when I opened the URL where I installed it).

I'm now bored with the manual and would like to start doing some of the things that it was talking about but there seems to be no link to open the application? Even the 'Getting Started' page was no help?

Is there really an underlying application or is it just all hot air?!

Kind regards

Peter


  Prototype Modal Window Redirection problem
Posted by: El Forum - 09-01-2007, 12:01 AM - No Replies

[eluser]millisami[/eluser]
I'm using prototype window for the login form.
This is the link that will create a model login window.

Code:
<a href="[removed]openModalDialog()">Click here to open a modal window</a>

function openModalDialog() {
debug($('modal_window_content'));
var win = new Window('modal_window', {className: "alphacube", title: "Login",  width:500, height:300, zIndex:150, opacity:1, draggable:false, resizable: false});
win.setAjaxContent('user/loginajax');
win.setDestroyOnClose();
win.showCenter();
win.show(true);
}
If the login fails, the error message is shown in the same modal window.
But the problem is, when the login is successful and in the function loginajax() if I put the code
Code:
redirect("/dashboard");
the content of the dashboard is loaded in the same windows instead of loading in the main parent window.
To overcome this, what I did is, I returned a responseText 'successfull' and compared it as follow
Code:
if (req.responseText == 'successfull') {
Windows.focusedWindow.destroy();
location.href='/dashboard';
}
But I don't think to load it via javascript location.href is a feasible way.
So, is there any other way to redirect and load the dashboard page in the parent window from the controller function itself?
Thanks


  Calendaring Class
Posted by: El Forum - 08-31-2007, 06:49 PM - No Replies

[eluser]webdude[/eluser]
Hello

Has anyone got a good working example of the Calendaring Class? I am trying to recreate something like the Google Calendar.

Also when using the Showing Next/Previous Month Links does it matter that I am using file extensions?

EG: mydomain.co.uk/calendar.html (really its a php page but i am using .html extensions in my config)

Thanks


  Problems with CI's tutorials, both the all-text version and the sexy video one
Posted by: El Forum - 08-31-2007, 06:27 PM - No Replies

[eluser]buffalobill[/eluser]
I posted the following message a few hours back as a response to Derek-the-Administrator's posting concerning tutorials and the like, and something tells me that that particular location was about as far away from 42nd & Broadway [42&B;was once the busiest intersection in NYC, maybe still is) as you can get, therefore I post it anew, but as a completely new thread, albeit, at the risk of thus working it threadbare :-)]. I should add that, with reference to the rant below, I did try and rearrange the folder path in the most obvious ways - by eliminating first the one sub-folder, then the other - but nothing helped. Anyways, I hope this problem gets more attention here, otherwise I will have to think up something more eye-catching [maybe a pornographic title?... note how the title to this thread has already inched a bit in that direction ;) ]...
.
.
.


Dear Derek,

I wish that CI’s own tutorials, the written one and the video one on form validation, were as well-functioning as those to which you refer on wiki (I assume the latter are well-funtioning, I haven’t seen them yet, but I can report that the CI ones just mentioned aren’t!). The QT player required to play the video tutorials (one on the CI methodology in general, the other on form validation, I presume - it concerns creating one’s blogsite in 20 minutes) just doesn’t work, even after updating the QT player and rebooting my machine (the video has excellent audio properties, but no imagery!). W.r.t. the “written” [NB: text-only] form validation tutorial, there is a problem with the folder paths listed. One is asked to create PHP files and place them in an applications/views and an applications/controllers folder, depending on the type, or function, of the file in question, and then to try and access those files with an URL that looks like so: <http://www.mysite.com/index.php/form/> (if it is the file entitled “form” which one is attempting to access).

First of all, nowhere in the tutorial is there mention of the creation of an index.php file, and one’s website is certainly not born with such a file, even if it is PHP-ready, as is my site (I can easily access PHP files on my site, just not via the folder path suggested by the CI tutorial). And perhaps more importantly, the tutorial files do not seem to link in any intuitive way to mysite.com/applications/(view or controllers, as the case may be). But perhaps even more critically, the view file (viz., there are “view” files and “controller” files, each with its respective function… uh, I mention this for the benefit of novices like me : } ), which is supposed to introduce the form (i.e., the user-input form around which the entire tutorial centers), does not contain any recipe for creating a form, only a “Welcome to my blog!” message.

Now, I can appreciate that the creator of this particular “view” form may have considered that it wasn’t so important to actually create an input form with the file (entitled “blogview"), yet I contend that, paedagogically [NB: SP!], it is imperative to do so when the audience is purportedly the novice - and it is not as if the code necessary to create such an input form is all that daunting; omitting it, for novices, is a cardinal sin!

I can follow other online tutorials (the folder paths are designated correctly), but they don’t divulge the entire code - crucial bits are concealed; one has to purchase the product in order to gain full insight, which is what first attracted me to CI’s tutorial, because all the code seemed to be there for the beginning tutorial (although I would have liked for it to be complete, in the sense that it was a complete PHP-based form validation exercise, such that when one was finished with the tutorial, one had a ready-to-insert form validation code, replete with form fields).

Yours,
buffalobill [because his last name is cody ["cody" < "code", get it? | : - } ]


  return false in model - how to use this info in controller
Posted by: El Forum - 08-31-2007, 04:15 PM - No Replies

[eluser]tinawina[/eluser]
Hi there - I'm putting together a comment form. It's in the first stages and so is pretty simple/straightforward. Once the comment is submitted, we want to update the user table's "comments" field which simply tracks how many comments a user has submitted. We'll use that # in displays throughout the site. With that done we want to just save the comment data to the comments table.

I'm running into a problem where I check to make sure that the dbase query to update the comment field in the user table was successful. If so, I want to do a few more things and then put up a success message. If not, I want to stop what I'm doing and show a failure message. I keep getting a success message even when clearly the database query didn't work -- as in, nothing is updated/inserted and I should see the failure message. Good news is, if the query did work everything goes as planned.

I gotta admit: return true/return false mystifies me when I use these in a model. How do I actually use "return false" in my controller when I get to it in my model? Total newbie question - thanks so much for any insight!

my controller:

Code:
class Comments extends Controller
{

    function Comments()
    {
        parent::Controller();
        $this->load->helper(array('url', 'form'));
        $this->load->library('validation');
        $this->base = $this->config->item('base_url');
        $this->css = $this->config->item('css');
        $this->tinymce = $this->config->item('tinymce_simple');
        $this->title = "What's your take?";
        $this->content_type = 'research_listing';
    }

    function index()
    {
        // The $display array is used to pass data to the view files.
        $display['title'] = $this->title;
        $display['base'] = $this->base;
        $display['css'] = $this->css;
        $display['tinymce'] = $this->tinymce;
        $display['editor'] = 'yes';
        $display['content_type'] = $this->content_type;

        // The $rules array is used to ensure we get the data we need. Part of the validation library.
        $rules['subject']    = "required|htmlspecialchars";
        $rules['comment']    = "required";
        $this->validation->set_rules($rules);

        // The $fields array is used to repopulate the form fields with the submitted data in case someone is sent back to the form.
        $fields['subject']    = 'Subject';
        $fields['comment']    = 'Comment';
        $this->validation->set_fields($fields);
        $this->validation->set_error_delimiters('<div class="error">', '</div>');

        if ($this->validation->run() == FALSE)
        {
            $this->load->view('comment_form', $display, array('error' => ' ' ));
        }
        else
        {
            $this->load->model('handle_comments');
            $this->handle_comments->add();
            if ($this->handle_comments->add() === FALSE)
            {
                $this->load->view('failure');
            }
            else
            {
                $display['subject'] = $this->input->post('subject');
                $display['comment'] = $this->input->post('comment');
                $this->load->view('success', $display);
            }
        }
    }

my model:

Code:
class Handle_comments extends Model {

    function Handle_comments()
    {
        parent::Model();
    // loading database library automatically.
    }

    function add()
    {

    // Find out how many comments are on file for this user -
        $user_id = $this->input->post('user_id');
        if ( $this->db->select('comments')->from('end_users')->where('id', $user_id) )
        {
            $query = $this->db->get();
            foreach ($query->result() as $row)
            {
    //    Increase the number in the "comments" field in End User table by one.
    //    The number is used in site page displays to show how many comments the user has posted to date.
                $comments = $row->comments + 1;
                $data = array('comments' => $comments);
                $this->db->where('id', $user_id);
                $this->db->update('end_users', $data);

    // Save new comment data.  For now, just hard-coding the user_id into a hidden form field.
                $data = array(
                                'user_id'        => $user_id,
                                'content_id'    => $this->input->post('content_id'),
                                'content_type'    => $this->input->post('content_type'),
                                'subject'        => $this->input->post('subject'),
                                'comment'        => $this->input->post('comment'),
                                'date_created'    => date('m-d-Y'),
                                'date_mktime'    => mktime(0,0,0,date('m'),date('d'),date('Y'))
                            );
                $add_data = $this->db->insert_string('comments', $data);
                $query = $this->db->query($add_data);
            }
        }
        else
        {
            return false; // when I get this, i try to pass it to the controller but clearly it's not getting there....
        }

    }
}


  how do you handle form submissions
Posted by: El Forum - 08-31-2007, 04:05 PM - No Replies

[eluser]jvittetoe[/eluser]
in my current application, once a user logins in they are redirected to their dashboard, via the dashboard.php controller. currently residing at www.myproject.com/dashboard

now from this page there is a link to modify settings. once clicked they are then routed to www.com/dashboard/settings - this function from within the dashboard controller loads a view file...

Code:
$template['mainContent'] = $this->load->view('dspSettings', $data, true);
        $this->load->view('layDash', $template);

now from the dspSettings view file there is a form. im using the ci form helper. the form is as follows...
Code:
&lt;?=form_open('dashboard/updateUserAccount'); ?&gt;
        <label for="modify_oldpassword">Old Passsword</label><br />
        &lt;input  type="password" name="password_old" id="modify_oldpassword" value="" /&gt;<br />
        <label for="modify_newpassword">New Passsword</label><br />
        &lt;input  type="password" name="password_new" id="modify_newpassword" value="" /&gt;<br />
        <label for="modify_confpassword">Confirm New Passsword</label><br />
        &lt;input  type="password" name="password_conf" id="modify_confpassword" value="" /&gt;<br />
        <label for="modify_firstname">First Name</label><br />
        &lt;input  type="text" name="firstname" id="modify_firstname" value="" /&gt;<br />
        <label for="modify_lastname">Last Name</label><br />
        &lt;input  type="text" name="lastname" id="modify_lastname" value="" /&gt;<br />
        <label for="">Delete Account?</label><br >
        &lt;input type="checkbox" value="0" id="modify_deleteaccount" /&gt;<label for="modify_deleteaccount" class="selectable">Check here to delete your account.</label><br />    
        &lt;input type="submit" value="Modify Settings" /&gt;
    &lt;/form&gt;

on submission, the form routes to the dashboard/updateUserAccount function:
Code:
function updateUserAccount(){
        
        $data['title'] = "My Finance ~ v1.00 ~ Dashboard";
        $data['status'] = "PLEASE LOGIN";
        
         $rules['password_old'] = 'trim|required';
          $rules['password_new'] = 'trim';
          $rules['password_conf'] = 'trim';
          $rules['firstname'] = 'trim';
          $rules['lastname'] = 'trim';
         $this->validation->set_rules($rules);
    
    
        $template['mainContent'] = $this->load->view('dspSettings', $data, true);
        $this->load->view('layDash', $template);
        
        if($this->validation->run() == FALSE){
            
                $data['status'] = "Invalid Login";
                redirect('/dashboard/settings/', 'refresh');
                
        } else {
            
            $password_old = $this->validation->password_old;
            $password_new = $this->validation->password_new;
            $password_conf = $this->validation->password_conf;
            $firstname = $this->validation->firstname;
            $lastname = $this->validation->lastname;
            
//DISREGUARD BELOW THIS LINE
//HAVENT GOT THERE YET

            if ($this->userAccountHandling->modifyUserAccount($password_old, $password_new, $password_conf, $firstname, $lastname)) {

                $data['title'] = "My Finance - v1.00";
                $data['status'] = "USER ACCOUNT FOUND - LOGGING IN";

                //USER ALREADY EXISTS
                //LOG USER IN
                if ($this->userAccountHandling->loginTheUser($emailaddress, $password) == TRUE) {
                    
                    //successful login
                    //$this->load->view('layMain');
                    redirect('/dashboard/', 'refresh');
                
                }
            }
        }
        
    }

the current url is www.com/dashboard/updateUserAccount which brings up errors telling me 'Undefined property: password_new' because that field was submitted empty. how can i keep the field optional and still modify a record in the database without running into errors like this.

im still new to the framework and developing in general. how is my structure. could i be doing these easier and faster? thanks.


  help with recursive function
Posted by: El Forum - 08-31-2007, 02:59 PM - No Replies

[eluser]kbauman[/eluser]
There's been a lot of discussion regarding the adjacency vs. nested sets method, for hierarchical data, so I know all about that. In fact I tried out both methods, and since I have a database I need to work with that uses the adjacency method I had to write a recursive function to put the data in order.

My problem is that if I put it in a library were I'd like it, or even in the model with the database functions, I get an error for the recursive calling of the function saying that it's not defined. Here's the function:

Code:
function create_menu($categories, $parent = 0, $i = 0, $base="gallery") {
      $result = array ();
        if ($categories) {
          foreach ($categories as $category) {
            if ($category->parent_id == $parent) {
                $level = $i;
                    $result[$category->id]['category'] = str_repeat("<ul><li>", ($level+1));
                    $result[$category->id]['category'] .= anchor("/$base/$category->category", "$category->category");
                    $result[$category->id]['category'] .= str_repeat("</ul></li>\n", ($level+1));
                    $children = create_menu($categories, $category->id, ($i+1), ($base."/".$category->category));
                    $result += $children;
            }
        }
        }
        return $result;
  }

What should I do? It only worked so far, when I was writing the function, if I had the database function, and this function all in the index function of my controller. I don't really want it there.


  Session library bug!
Posted by: El Forum - 08-31-2007, 01:44 PM - No Replies

[eluser]alpar[/eluser]
Please refer to this thread . Sorry for posting it in the wrong place. I think this is a serious problem... please comment

PS: Problem to reveal best on MACs and IE


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Ajax post failing with Ty...
by PaulC
30 minutes ago
MVC vs MVCS vs CodeIgnite...
by FlavioSuar
2 hours ago
CodeIgniter Shield 1.0.0 ...
by timesprayer
8 hours ago
Website Traffic Drop Afte...
by InsiteFX
8 hours ago
Magic login link not work...
by InsiteFX
9 hours ago
Is codeigniter 5 upco...
by InsiteFX
9 hours ago
CI4 Auto-Discovery not wo...
by InsiteFX
Yesterday, 11:04 PM
Why PHP is still worth le...
by InsiteFX
Yesterday, 10:55 PM
Any user guid or video o...
by msnisha
Yesterday, 02:30 PM
Why Every Programmer Need...
by Yetkiliteknikservis
Yesterday, 01:49 PM

Forum Statistics
» Members: 145,126
» Latest member: thabett88
» Forum threads: 78,385
» Forum posts: 379,433

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB