Welcome Guest, Not a member yet? Register   Sign In
[Q] another loading views from DB
#1

[eluser]vlad_ci[/eluser]
Hi, I am new to CI

Working on an application where there is a series of config 'Wizards'
each wizard has several pages.
I allow users to store in a database number of pages,
the field types and field names for each page.
and the overall 'look' of the pages in a particular wizard.

Basically the data in the database is stored in such a way that it
will need to be 'enriched' into a complete 'PHP' page.

And then I was hoping that I can use those PHP pages
as 'viewes'.

I have read this post
http://ellislab.com/forums/viewthread/80517/

and it looks like the final thing there was that the View system
in GI would not allow to 'execute' within PHP a PHP script
(that is I can not have a string variable that has a PHP script
and tell to CI that this is my 'view' so run with it)


I just wanted to ask if it is still the case, and if there are suggestions within CI or outside CI how to do that (without much
effort of course :-) )

thanks in advance
#2

[eluser]hvalente13[/eluser]
Hi vlad_ci,

I guess that the older CI and forum users, would tell you to read more the user guide. I recommend that too, and if you notice it's one of the best user guides for this kind of software (framework).

But I give you a hint:

1. Use the models to retrieve all data you want from database. If you want, you may also build the html elements inside the model functions like selects and other tags.

2. Use the controllers to work that data according with the "state of the world".
Here you can make ifs and other conditions, controlling the uri->segments and POST variables, and pass the data to an array. You can reach the data by calling the model:

Code:
$data['example'] = $this->mymodel->getdata($this->uri->segment(3))

3. THIS YOU MIGHT WANT TO KNOW.

Here you put all your data with the names you gave previously in you controller array $data

Code:
<?=$example?>

And if you want to pass a new variable to the view just create it in your controller like this:
Code:
$data['var1'] = "My website rules";

Then you can put it in your view like this:

Code:
<div>&lt;?=$var1?&gt;</div>

Hope this helps!

Good luck
#3

[eluser]vlad_ci[/eluser]
Thank you,

I understand that in viewes the CI substitues
'macro' variables in the view with the values generated in the model
or controller.

So in your example you are passing the values via the $data
array.


What I was asking is if I can do this



$my_string_I_just_created=my_db.get_view_mockup_from_db();
$this->load->view($my_string_I_just_created);

I may be missing it but I just did not see an example
where the CI view class can load the php file representing
the view -- not from a file residing in /viewes directory
but from a string.


There are a couple of reason why I am looking to do something
like this
one is that my users can specify the input fileds their names
and the overall look of the wizards -- and I store that in the database.

Second, what I would like to do is to somehow use the
code igniter to cache the pages (because they will not change
for each wizard).

... EDIT ...
or may be what you meant is that my view.php would just have
a one line something like

my_simple_view.php

&lt;?php echo $my_view_data;?&gt;

and then I would just do


$data['my_view_data'] =my_db.get_view_mockup_from_db();
$this->load->view('my_simple_view',$data);

?

thanks in advance,
vlad
#4

[eluser]hvalente13[/eluser]
Quote:or may be what you meant is that my view.php would just have
a one line something like

my_simple_view.php

&lt;?php echo $my_view_data;?&gt;

and then I would just do

$data[’my_view_data’] =my_db.get_view_mockup_from_db();
$this->load->view(’my_simple_view’,$data);

?

Yes... that's it! You have to pass the info from controller to the view via an array! Simple as that.

Of course you can instantiate any var in your view and work with it, but in this case what's the point of MVC architecture? I only do that for some counter vars to determine if it's odd or even... For the rest I work all data in my models -> controllers.

Hope this helps.

Good luck




Theme © iAndrew 2016 - Forum software by © MyBB