Welcome Guest, Not a member yet? Register   Sign In
Dynamic Content in CI
#11

[eluser]seismic[/eluser]
I'll anlayze your suggestions. Thank you guys.
Cheers.
#12

[eluser]DJMOHNL[/eluser]
Hey.

i thought i might give you some suggestion with making dynamic php views.

Code:
<?php

class Test extends Controller {
  function Test() {
    parent::__construct();  
    
    // this is where you load your helper, library, or models.
    // you can also put them in your config file located on application/config/config.php
    
  }      

  function index() {
    
  }

  // this is a test function called myview, you can also rename it for your application
  // its only for showing you how i normally work.
  //$my2nd section is normally "NULL", this means it can be blank and showed as:
  // http://yoursite.com/test/mycontrol
  // it can be given a uri segment parameter this means that you can fill it in in your adressbar
  // and show a specific file (view file)
  // for example you want to see your "2nd article" you put in uri:
  // http://yoursite.com/test/mycontrol/2

function mycontrol($my2ndsection = NULL) {
    // this example without model. the best is to load it in the child controller construction (the function called "Test" above!)
    
    // here we tell the view file to use this variables to show the usere specific content
    $data['articleId'] = $this->uri->segment(3, 0);

    // here you load the view files and give the variables to it.
    // i personally create sections out of the view files, this means that my view files
    // keep cleaner and less heavy. the 1st view file is the header, 2nd your specific
    // controller view file, 3rd view is the footer.
    $this->load->view('header');// note this is the header file
    $this->load->view('yourAdditionalFolderName/YourViewFileName', $data);// your view
    $this->load->view('footer');// this is the footer
  }
}
?>

So now we have created a controller with a specific article id to show.
We can go on and make the view file and generat the content thats needed for your users.

So lets show the view file.
Code:
<?php
// here is the php function set to get the content the user wants.
// the $articleId is the shortTag version of the $data['articleId'] this is possible with // CodeIgniter
if($articleId = 1)
{
// make a code for showing the 1st articleId
// you can use a model file/function if its loaded.
echo "<h4>This is content 1, please read on.. and click on content 2 link</h4><br />";
}
if($aricleId = 2)
{
// put your code here to show articleId 2, as the 2nd article
// you can use a model file/function if its loaded.
echo "thanks for reading on.. and place your comments below in a comment box<br />";
}
?&gt;
// as my header has been loaded, i normally only have to put some like:
<div id="someid">
<p>

  This is the base content, you can choose a link to show the 2nd article.<br />
<a href="&lt;?=base_url('test/mycontrol/1')?&gt;">Go to article 1</a>

<a href="&lt;?=base_url('test/mycontrol/2')?&gt;">Go to article 2</a>

<a href="&lt;?=base_url('test/mycontrol/3')?&gt;">Go to article 3, wich currently doesnt exist</a>

</p>
</div>

So thats how i normally do it, its a professional way. Not completely explained, just show it shortly. It can be fast and professional with CI, if you just make sure it can be handled. You could try the 'try, catch, break' functionality of php inside CI to make it better to overlook it.

I hope you could use this, i prefer the way you use header, menu, controllerview and footer pages seperate. It just makes life easier!
:coolsmile:
#13

[eluser]Phil Sturgeon[/eluser]
If you hard-code it why not use slugs? And why not do this in a DB? Seems a VERY rudimentary way to handle news articles.
#14

[eluser]DJMOHNL[/eluser]
Its just for showing purposes, if you read well youll notice all the info. You can use this way to edit your CI scripts with usage of models, views, controllers (MVC)! Just place the model ($this->load->model('mymodel')) in the top of the controller function name Test.
then use your model code, loading your content on your view page.

might be usefull for pages with multiple diffrent content. Just look at it carfully, you should be able to make your way the easiest way to use your MVC CodeIgniter efficiently.

good luck.
#15

[eluser]Unknown[/eluser]
[quote author="stuffradio" date="1260407765"]KISS (Keep it simple stupid)

Models -> Handles all database transactions
Views -> All the stuff that gets outputted to your brwoser
Controllers -> Controls what happens, logic can happen in here too.

You can store content for certain pages in a database.

Say you have page A, in your browser path you can go

http://mysite.com/index.php/page/index/A

You take the value from the 3 segment, that's the value A.

You go to the model and fetch the data for page A. You store the values of page A in variables and load them onto the view.

Try playing around with that concept, I have to go to school now... I'm sure others can help if you have other questions while I am gone.[/quote]

I really need a post-it with KISS in sharpie on my desk...
#16

[eluser]DJMOHNL[/eluser]
maybe an idea.. to open a efficiency topic..Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB