CodeIgniter Forums
Model View Controller problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Model View Controller problems (/showthread.php?tid=24158)



Model View Controller problems - El Forum - 11-01-2009

[eluser]jabga[/eluser]
Hi all. I integrated TinyMCE editor in my add article view.
And javascript in the header is here
Code:
script type="text/javascript" src="http://<?php echo $_SERVER['HTTP_HOST']?>/ci/tiny_mce/tiny_mce.js"

When I am adding an article using this, image url's are not correctly. They are not viewing

TinyMCE folder is in the main root, with index.php and system folder.
Guys please tell me how should I handle with this?

And also tell me where should I position my css files and how to write their url's dynamic?
I mean, I would like it to works correctly when after uploaded to my Web host.


Model View Controller problems - El Forum - 11-01-2009

[eluser]imn.codeartist[/eluser]
load url helper in autoload

then use

Code:
script type="text/javascript" src="http://<?php echo base_url();?>/ci/tiny_mce/tiny_mce.js"



Model View Controller problems - El Forum - 11-01-2009

[eluser]jabga[/eluser]
Tnx,
Code:
<?php echo base_url();?>
returns http://localhost/ci
nice


Model View Controller problems - El Forum - 11-01-2009

[eluser]jabga[/eluser]
I have another one problem.
I would like to redirect to the last article when published a new article.

All are working, just can't know the last article ID number.
this is my Add article controller function
Code:
function add_article_sub ()
    {
        $this->db->select_max('id');
        $query = $this->db->get('blog');
[b]        $lastarticle = $query->id ;[/b]
        $this->Blog_model->insert_entry();
        redirect('blog/article/'.$lastarticle);
        
    }
Please correct the Bold area.






And also one question, can I insert varuable within this?
Code:
$data['query'] = $this->Blog_model->get_last_entries();
For example, How can I show the last $var entries?
It should be like this I think:
Code:
$this->Blog_model->get_$NUM_entries();
My model is here
Code:
function get_last_ten_entries()
    {
        $query = $this->db->get('blog', 10);
        return $query->result();
    }
Maybe it can be like this
Code:
function get_last_$NUM_entries()
    {
        $query = $this->db->get('blog', $NUM);
        return $query->result();
    }
i would like to be able change function name and number of showing post dynamically


Model View Controller problems - El Forum - 11-02-2009

[eluser]saidai jagan[/eluser]
use this,
$this->db->insert_id();
It returns the Lat added blog id (must be Primary key).

// second one
$this->Blog_model->get_last_entries();

Use like theis
$this->Blog_model->get_last_entries('10');


Model View Controller problems - El Forum - 11-02-2009

[eluser]jabga[/eluser]
[quote author="saidai jagan" date="1257169905"]use this,
$this->db->insert_id();
It returns the Lat added blog id (must be Primary key).

// second one
$this->Blog_model->get_last_entries();

Use like theis
$this->Blog_model->get_last_entries('10');[/quote]
I used first one, it works! Thanks.

Please, can you answer my last question? It's here
can I insert varuable within this?
$data['query'] = $this->Blog_model->get_last_entries();

For example, How can I show the last $var entries?
It should be like this I think:
$this->Blog_model->get_$NUM_entries();

My model is here
function get_last_ten_entries()
{
$query = $this->db->get('blog', 10);
return $query->result();
}

Maybe it can be like this
function get_last_$NUM_entries()
{
$query = $this->db->get('blog', $NUM);
return $query->result();
}

i would like to be able change function name and number of showing post dynamically


Model View Controller problems - El Forum - 11-02-2009

[eluser]saidai jagan[/eluser]
hai u want to display the no.of records dynamically as the user selects like 3,5,10 etc ?

use this,
$no_of_records = 5 // which the user selects
$this->Blog_model->get_last_entries($no_of_records);

function get_last_entries($limit)
{
$query = $this->db->get(‘blog’, $limit);
return $query->result();
}


Model View Controller problems - El Forum - 11-02-2009

[eluser]jabga[/eluser]
[quote author="saidai jagan" date="1257171001"]hai u want to display the no.of records dynamically as the user selects like 3,5,10 etc ?

use this,
$no_of_records = 5 // which the user selects
$this->Blog_model->get_last_entries($no_of_records);

function get_last_entries($limit)
{
$query = $this->db->get(‘blog’, $limit);
return $query->result();
}[/quote]
Yes. I would like to display the no.of records dynamically as the user selects.

Our function get_last_entries($limit) is in the model. Please see the $limit varuable, I would like to declare it in controller, and I tried to do, but it's not working.
How can I declare the Limit varuable in the controller?


Model View Controller problems - El Forum - 11-02-2009

[eluser]jabga[/eluser]
No no it's working. Very nice. Thanks Big Grin

Now, I would like to insert pagination in my frontpage.
I already inserted CI pagination in my single article pages

I have 80 articles now and last 10articles showing on front page.
and would like to show 10 news on one page.

I guess I get second url segment and add something on my model page.
I need someone's help, please give me some idea.