• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is'this correct? (Load content from a view)

#11
[eluser]deviant[/eluser]
Yeah that would work, although you would want to call it MY_Controller instead of New_controller unless you change the prefix in the configuration file.

#12
[eluser]ariok[/eluser]
in first i think i need to read with more attention the documentation Big Grin ..

than.. ok it works .. but i think i'm in the same situation ... because now in all of "my_controller" child, i need to set something like
Code:
$data['information']=parent::$information;
$data['content']="some content..."

and than load main view passind $data ...
or i'm i wrong?

maybe i could set a $data variable in my_controller and extend this variable in his child with contents..

#13
[eluser]CI TaMeR[/eluser]
Why make it easy when you can complicate thinks! Is that your motto or is there a special reason why you can't do it the CI way?

#14
[eluser]ariok[/eluser]
[quote author="CI TaMeR" date="1186506287"]Why make it easy when you can complicate thinks! Is that your motto or is there a special reason why you can't do it the CI way?[/quote]

Eheheh i understand what you feel reading my posts..
but the initial purpose was exactly to understand how to do this thing in CI..

So the question is :

How is possible to load content in a view shared by more controllers without set this content in all controllers??

Example :
Main view
Code:
//VIEW main_tpl.php
<?
.
.
.

<p>*HERE I NEED A CONTENT FROM DB*</p>
<p>&lt;?$content?&gt;</p>
.
.
.
?&gt;

And 2 controllers... which share view below described..
Code:
class Home extends Controller {
    function index(){
        
    }
    
    function Home() {    
        parent::Controller();
        $this->load->helper('url');    
        $data['content'] = SOME CONTENTs..
        $this->load->view("main_tpl",$data);
    }
}

class Contacts extends Controller {
    function index(){
        
    }
    
    function Contacts() {    
        parent::Controller();
        $this->load->helper('url');    
        $data['content'] = SOME CONTENTs..
        $this->load->view("main_tpl",$data);
    }
}

How make it easy ?

#15
[eluser]deviant[/eluser]
If you are just using a lot of generic pages with the contents stored in a database there is no point in making a Controller for each page. Just make one Controller, route the URIs to that Controller and do everything else in that single Controller instead of making loads of them. For example make a Controller called Content, route URIs containing home and contacts to it, and then use the URI segments to figure out which contents to load from the database.

#16
[eluser]ariok[/eluser]
i prefer to mantain one controller for one content .
Here i showed you only a simple example to understand how to do some things in CI.. but i think that in more complex sites i need to use one controller for one content , so i prefer to learn now that i'm at the beginning how to do the right thing Big Grin

#17
[eluser]CI TaMeR[/eluser]
Why don't you explain to us why you need many controllers for one view?
Because it does not make sense what you are saying

#18
[eluser]ariok[/eluser]
Do You say that is better if i use a single controller for all site .....ok Tongue

I think that if i have a website with 50 sections which share a view, it's strange have to use a single controller and load a file with 2000 rows of code...when i can load a single file of 40 rows.

But if is the right way with CI ,ok i confide in you, as you can see i'm really new in CI but this way sound a little out of standard programming principles.

you understand what i mean?

#19
[eluser]ariok[/eluser]
uhm.. read at this post.. http://ellislab.com/forums/viewthread/55693/#274225 here people say that is not a good idea to use a single controller...

NOW I'm really confuse..

P.S.
I would like to specify that this's not a way to criticize, on the contrary i appreciated your help and i would like to understand which is the better method to do this work Big Grin


Thank you again for your patience an sorry for my poor english Tongue

#20
[eluser]deviant[/eluser]
It really all depends on the logic of your Controllers. If you are just pulling data out from a Model and dumping it into a view then there is nothing wrong with a single Controller, but if you are performing lots of different operations on the data you get from the Model on each different page before putting it into a view then yes you will need multiple Controllers.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.