Welcome Guest, Not a member yet? Register   Sign In
  Trying to extend Loader to call app controllers
Posted by: El Forum - 06-28-2007, 04:21 AM - No Replies

[eluser]Stuart Marsh[/eluser]
Hi everyone.
I'm fairly new to CodeIgniter but I am already impressed by how flexible and easy it is.
However like many people on here I am disappointed that I cannot call controllers within controllers. I know it goes against the MVC structure and that helpers can be created but this would be a much more flexible way to do things.
So I have started to play with CodeIgniter and I'm trying to extend the Loader library so I can call other controllers. I have a library in my app called MY_Loader.php and this is what I have put in it:

Code:
class MY_Loader extends CI_Loader {
    
    /**
     * Constructor
     *
     * @access    public
     */
    function MY_Loader()
    {
        parent::CI_Loader();
    }
    
    /**
     * Controller Class Loader
     *
     * This function lets users load and instantiate controller classes.
     * It is designed to be called from a user's app controllers.
     *
     * @access    public
     * @param    string    the name of the class
     * @param    mixed    the optional parameters
     * @return    void
     */    
    function Controller($library = '', $params = NULL)
    {        
        if ($library == '')
        {
            return FALSE;
        }

        if (is_array($library))
        {
            foreach ($library as $class)
            {
                $this->_ci_load_controller_class($class, $params);
            }
        }
        else
        {
            $this->_ci_load_controller_class($library, $params);
        }
        
        $this->_ci_assign_to_models();
    }

    // --------------------------------------------------------------------
    
    /**
     * Load Controller class
     *
     * This function loads the requested controller class.
     *
     * @access    private
     * @param     string    the item that is being loaded
     * @param    mixed    any additional parameters
     * @return     void
     */
    function _ci_load_controller_class($class, $params = NULL)
    {    
        // Get the class name
        $class = str_replace(EXT, '', $class);

        // We'll test for both lowercase and capitalized versions of the file name
        foreach (array(ucfirst($class), strtolower($class)) as $class)
        {            
            // Lets search for the requested library file and load it.
            $is_duplicate = FALSE;
            for ($i = 1; $i < 3; $i++)
            {
                $path = ($i % 2) ? APPPATH : BASEPATH;    
                $fp = APPPATH.'controllers/'.$class.EXT;
                
                // Does the file exist?  No?  Bummer...
                if ( ! file_exists($fp))
                {
                    continue;
                }
                
                // Safety:  Was the class already loaded by a previous call?
                if (in_array($fp, $this->_ci_classes))
                {
                    $is_duplicate = TRUE;
                    log_message('debug', $class." class already loaded. Second attempt ignored.");
                    return;
                }
                
                include($fp);
                $this->_ci_classes[] = $fp;
                return $this->_ci_init_class($class, '', $params);
            }
        } // END FOREACH
        
        // If we got this far we were unable to find the requested class.
        // We do not issue errors if the load call failed due to a duplicate request
        if ($is_duplicate == FALSE)
        {
            log_message('error', "Unable to load the requested class: ".$class);
            show_error("Unable to load the requested class: ".$class);
        }
    }
Basically it is a copy of Library and _ci_load_class but with the controller directory. This means controllers I can call the controller with $this->load->Controller('Controller_filename') then $this->controller_name->function(). However, when these 'sub' controllers try to use models or helpers they fail.
For example, If the controller I access uses a model I get the following message.
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Form_Model::$db

Filename: models/form_model.php

Line Number: 21

Could anybody help me get this working or help me understand why it is failing?


  Fatal error: Allowed memory size...
Posted by: El Forum - 06-27-2007, 11:39 PM - No Replies

[eluser]leon_dewey[/eluser]
Having a memory limit problem,

Their shouldnt be a problem as i incressed the limit to 200megs.... ( i know its over kill )


Fatal error: Allowed memory size of 209715200 bytes exhausted (tried to allocate 112108305 bytes) in /data/********/httpdocs/survey/system/libraries/Parser.php on line 146


Any one have any ideas why this would happen?


  gmt_to_local() returns incorrect date
Posted by: El Forum - 06-27-2007, 11:37 PM - No Replies

[eluser]the real rlee[/eluser]
Hi guys,

I'm having weird issue with the date helper in CI. gmt_to_local() with correct timezone (UP10) is not showing the correct date, however PHP's gmdate IS showing the correct date.

What's possibly wrong here?

FYI Im using XAMPP on my local machine


  noob question
Posted by: El Forum - 06-27-2007, 10:06 PM - No Replies

[eluser]jstrebel[/eluser]
Hey there.. noob here.

I am trying to build a 3 level deep url loading a view at each stage.


My controllor for a user dashboard: dash.php

Code:
function index() {
                $data = array(
                        'morecontent' => '',
                );

                $content = $this->load->view('dash/index',$data,true);
                $this->wrapOutput($content,"Dashboard","dash");
        }
This gives me http://somesite.com/dash

So there is sub section of the dashboard called the account settings

Code:
function settings() {
                
                $data = array(
                        'morecontent' => $this->load->view('dash/settings',array(),true),
                        
                      
                );

                $content = $this->load->view('dash/index',$data,true);
                $this->wrapOutput($content,"Dashboard > Settings","dash");
        }
So above I am loading the settings view into the dash view... and it gives me http://somesite.com/dash/settings

So I want to now load a payment view into settings.. and have the final url be http://somesite.com/dash/settings/payment

My instinct is to create a function called payment() inside of the settings() function.. sort of like nesting folders in a file strcture... but that is not how CI works.

I need to have 3 or 4 subpages inside of settings, that is inside of dash... How best to accomplish this?

Sorry if it does not make sense.. I am thinking like a file system.. if I want to group pages into categories I just nest the file structure... how does one nest functions in a controllor to created nested url's?

It is important for us to use this 3 level structure as /dash will have many 2nd level pages which in turn have more 3rd level pages. like /dash/profile/bio and /dash/profile/privacy etc.


  Validation problem, maybe server problem
Posted by: El Forum - 06-27-2007, 09:32 PM - No Replies

[eluser]Référencement Google[/eluser]
Hi,

I get a problem with a simple form to validate.
In local it's perfectly working, but once on the prod server, impossible to make it work.

In my view form i have things like:

Code:
&lt;?=$this->validation->prenom_error?&gt;

And once on the production server, i get errors like :

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: prenom_error

Filename: contact_form/contact_form.php

Line Number: 8

Can somebody help me ?


  How to call functions of another controller
Posted by: El Forum - 06-27-2007, 08:33 PM - No Replies

[eluser]yongkhun[/eluser]
Is there a way to call the functions of another controller from a different controller? I try to do like $this->another_controller->function1() but error said "calling function on non-object". How? Thanks!


  Is this correct way...
Posted by: El Forum - 06-27-2007, 03:25 PM - No Replies

[eluser]mk3[/eluser]
I found solution. how to include in every page login form, but do not really know if it is correct. the method I used is I auto loaded library. and the library constructor is doing the following:

Code:
class Authorize {
    
    //constructor    
    function Authorize(){
        $this->CI =& get_instance();
        $this->CI->load->library('MySmarty');
        $this->CI->load->library('session');
        $this->CI->mysmarty->assign('login_errors', null);
        $this->CI->mysmarty->assign('user', $this->CI->session->userdata('user_data'));
        $this->CI->mysmarty->assign('logged_in', $this->CI->session->userdata('logged_in'));
        if (isset( $_POST['submit']) && $_POST['submit'] == 'Login'){
            $this->login();    
        }
    }

So when login form is submitted authorize library calls function which then processes login.

What it is interesting for me am I doing the right way. It seems OK for me, but I believe there are/can be some issues why this cannot be done.

Also would be nice to hear suggestions and critics.


  use of array data in views
Posted by: El Forum - 06-27-2007, 12:52 PM - No Replies

[eluser]pmonty[/eluser]
My array looks like this:

Quote:$formdata('sort'=>'perf-desc')
I am loading the view like this:
Quote:$this->load->view('testform',$formdata);
My view code looks like this:
Quote:Sort By: <select name="sorton">
<option value="perf-desc" &lt;?= if ($sort =="perf-desc") ? "selected='selected'" : "selected=''";?&gt; >Perf Desc</option>
</select>
Obviously I am doing something syntactically wrong to get this error:
Quote:Parse error: syntax error, unexpected T_IF in \system\application\views\testform.php on line 10

How should this be coded?

Paul


  Calender Lib for JS Form Input?
Posted by: El Forum - 06-27-2007, 11:07 AM - No Replies

[eluser]Phil Sturgeon[/eluser]
Anyone made a nice little form input GUI for dates in a form?

Would love something similar to phpMyAdmins calender view (that's the first example that came to mind) so instead of having multiple dropdowns or just a text input box i could have a lovely calender view.


  log files
Posted by: El Forum - 06-27-2007, 09:43 AM - No Replies

[eluser]Unknown[/eluser]
Is there something comparable to like an OC4J(java) log for CI? It would be beneficial when developing if I could see what is executing.

Suggestions are greatly appreciated.

Thanks.


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

Username
  

Password
  





Latest Threads
Validation | trim causes ...
by kenjis
1 hour ago
Integrating Bootstrap 5 i...
by Bosborne
2 hours ago
Error / Shield 1.0.3 + Ci...
by kenjis
3 hours ago
Asset Minification Packag...
by tarcisiodev1
Yesterday, 05:11 PM
Modify users data as an a...
by luckmoshy
Yesterday, 04:56 PM
Is it possible to go back...
by ejimenezo
Yesterday, 11:49 AM
SQL server connection not...
by davis.lasis
Yesterday, 07:11 AM
Problem with session hand...
by Julesb
Yesterday, 04:13 AM
External script access to...
by PomaryLinea
Yesterday, 03:58 AM
VIRUS reported after Chro...
by InsiteFX
04-25-2024, 11:34 PM

Forum Statistics
» Members: 85,543
» Latest member: irstaxxrelief
» Forum threads: 77,586
» Forum posts: 376,029

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB