Welcome Guest, Not a member yet? Register   Sign In
  run controller on show_404() of Exception
Posted by: El Forum - 02-26-2008, 06:12 AM - No Replies

[eluser]nirbhab[/eluser]
hi guys,

Is any method to run a controller class, on 404 CI error,
note: i don't want to redirect.

i want

Code:
http://domain.com/xxx/yyy/zzz/blab/blab.html
to run a specific controller.
if i redirect than , my url will change,i want the users to get the page displayed!

Too many thankx in advance.


  New to CI, have some questions
Posted by: El Forum - 02-26-2008, 05:20 AM - Replies (15)

[eluser]Kilroy[/eluser]
Hello!

I recently discovered CodeIgniter, and for the last couple of days I've been playing around a bit with it. My plan is to find a nice php framework that allows me to separate presentation, data and logic and eventually migrate an entire website to it.

However, I encountered problems right away. For creating the main menu, I have a system where the "current" link gets a class tag, like this: <a href="something.php" class="active">Some link</a>. This is based on the filename, and the logic looks something like this: if($filename == 'something.php') echo 'class="active';

Now, I wouldn't know how to do this with CI, since it always loads from index.php. My first idea was to compare it to the first segment of the URI instead of the filename, but that wouldn't work either, since having a default controller permits URIs without a first segment.

My second idea was to set a variable in the controller, so the view will know which controller called it. I haven't tried this yet, but I am sure it would work, even though it would not be a very elegant solution. How do you solve this?

Anyway, on to my next question. I have quite lots of things that simply need fetching from a database. Say I want to get the content-field from a table called 'news' where the id is 5. Right now, I do it this way (don't mind the tinymce-code):

Code:
$row = $this->db->where('id', 5)->get('news', 1);
$row = $row->row();
$data['news'] = $this->tinymce->echo_tinymce($row->content);
It gets sort of repetative if you have 5-6 (or even more) of these per controller. Tongue Is there a better way of accomplishing this?

Of course there aren't only drawbacks with CodeIgniter, it would probably be a huge lift for my administration system.

Just a last question. If I have tons of data that I need to pass to the view, is passing it through $this->load->view('someview', $data); the only way? It seems like this is a huge waste of memory.

Kilroy


  languages in application
Posted by: El Forum - 02-26-2008, 05:17 AM - Replies (8)

[eluser]chejnik[/eluser]
Hello, I would like to ask you what is the best way to use different languages in application.

I would prefer the users choose their language at the beginning in form element.
How can I change the language?

I have tried this with autoload of the language files with deafult language in config file

Code:
$this->config->set_item('language', $_POST["lang"]);

but no change in languages.

I have tried this with same result
Code:
$this->lang->load('user', $_POST["lang"]);

And second question - is it good idea to load all languages files or is it better to load them one by one? I expect there will be just 4 languages with 10 files with 100 strings.

Thanks Ales


  URI Routing, best way to do that
Posted by: El Forum - 02-26-2008, 05:13 AM - Replies (4)

[eluser]daweb[/eluser]
I everybody,

I have to read from a DB some records and I have to build my dynamic query based on uri segments. (and some $_POST values...)

I have, for example:

http://www.my-site.com/buy

http://www.my-site.com/sell

http://www.my-site.com/buy/car

http://www.my-site.com/sell/motocycle/red

http://www.my-site.com/buy/dog/big/italy...g-name/123

I want to build the query in just one controller...

Is it the right way to make: ?

$route['buy/(:any)/(:any)/(:any)/(:any)/(:any)'] = 'home/$5';
$route['sell/(:any)/(:any)/(:any)/(:any)/(:any)'] = 'home/$5';

$route['buy/(:any)/(:any)/(:any)/(:any)'] = 'home/$4';
$route['sell/(:any)/(:any)/(:any)/(:any)'] = 'home/$4';

$route['buy/(:any)/(:any)/(:any)'] = 'home/$3';
$route['sell/(:any)/(:any)/(:any)'] = 'home/$3';

$route['buy/(:any)/(:any)'] = 'home/$2';
$route['sell/(:any)/(:any)'] = 'home/$2';

$route['buy/(:any)'] = 'home/$1';
$route['sell/(:any)'] = 'home/$1';

$route['buy'] = 'home';
$route['sell'] = 'home';

What's the best solution to make this?

I'm very sorry about my english...

Will be better tomorrow... :-)


  Flashdata??
Posted by: El Forum - 02-26-2008, 01:42 AM - Replies (4)

[eluser]mikeyhell[/eluser]
I'm calling a set_flashdata on a page. The sessions are automatically loaded and I've had no problems with them, but when I try to set this it returns the error:

Code:
$this->session->set_flashdata('error', "The username/password combination did not match.");

Error message:
Fatal error: Call to undefined method CI_Session:Confusedet_flashdata()

Any ideas?


  After Redirect Post Data still remains
Posted by: El Forum - 02-26-2008, 12:40 AM - No Replies

[eluser]mikeyhell[/eluser]
I'm new to CI, but it seems strange that after a redirect('thispage') my post data still remains. Is there something i'm missing here or not doing correctly as I have not had this problem before w/ multiple submits from the same form being possible.


  Calling a controller after validation error
Posted by: El Forum - 02-25-2008, 11:30 PM - Replies (2)

[eluser]palaniappanc[/eluser]
I generate my pages by calling multiple views (header, form, footer). How would I get this page back after validation? I don't want to call all the views again (code duplication). Is there a way to call a controller (something like $this->call->controller('formpage') on form error, passing all the error messages to it and it's views?

Thanks.


  Need a helping hand with CI Routes
Posted by: El Forum - 02-25-2008, 10:11 PM - Replies (2)

[eluser]systemsos[/eluser]
Howdy everyone,

Just after a little bit of help with CI's routes. I have the following setup.

I have a main controller, which handles dynamic menus and their content. So in my example I'm re-doing my website (it desperately needs my love and attention and not a 2 minute hack).

I have the following things redirect to the default controller - which determines what section we're looking at, and what page of that section we're looking at.

I have;
/domains
/domains/some-pages
/hosting
/hosting/some-pages
/another-thing
/another-thing/and-it's-pages

Now I've been using routes for ['domains'] and pushing it back to my default controller, but that requires me to edit the routes.php file itself any time a new section is added.

As far as CMS goes - I don't like that idea.

I could use no route - and create a proper handling controller so that my site was
mysite.com/site/domains - but I want to remove the /site/ all together.

So now I've added a [':any'] and [':any/:any'] clause in my routes config. Which pushes "everything" back to the default controller. But I want "blog" for example to not be pushed there.

So I add a ['blog'] = "blog"; to goto that controller instead. But then if I goto /blog/something it doesn't work.

If I add ['blog/:any'] = "blog" - it just pushes it back to the default controller (and the index function) rather than where I would want it to go (it's normal function).

This isn't a problem at the moment, but I just thought I would see if anyone else has done something similar to what I'm trying to do.

Cheers for your thoughts Smile

[i]Edit: I have been trying to do something like $route['blog/:any'] = "blog/$2" but I don't actually know the proper setup for this.


  Model
Posted by: El Forum - 02-25-2008, 07:57 PM - Replies (2)

[eluser]Unknown[/eluser]
Hello

Can someone tell me how to run a Model example, I cant get it working.

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Blog::$load

Filename: controllers/blog.php

Line Number: 8

Fatal error: Call to a member function database() on a non-object

Code:
&lt;?php

class Blog extends Controller {

    function blog()
    {
    
$this->load->database();

   $this->load->model('blog', '', TRUE);
    
    $data['query'] = $this->Blog->get_last_ten_entries();

        $this->load->view('blog', $data);
    }
}
?&gt;

Code:
&lt;?php

class Blog extends Model {

    var $title   = '';
    var $content = '';
    var $date    = '';

    function Blog()
    {
        // Call the Model constructor
        parent::Model();
    }
    
    function get_last_ten_entries()
    {
        $query = $this->db->get('entries', 10);
        return $query->result();
    }
?&gt;

Code:
&lt;html&gt;
&lt;body&gt;
&lt;?php foreach($data as $item):?&gt;
&lt;?php echo $item;?&gt;
&lt;?php endforeach;?&gt;    
&lt;/body&gt;
&lt;/html&gt;


  db_session and set_flashdata problem
Posted by: El Forum - 02-25-2008, 07:54 PM - Replies (11)

[eluser]Unknown[/eluser]
Hello,
I'm having problems displaying session flashes.

This is what I have:

Code:
function index()
{
    $data['msg'] = $this->db_session->flashdata('msg');
    $this->layout->view('my_view', $data);
}
function add()
{
    $this->db_session->set_flashdata('msg', 'Item added!');
    redirect('thiscontoller');
}


I'm using FreakAuth for authentication and when I use above code, it clears the sessions and logs me out by displaying the login page. Any ideas?


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

Username
  

Password
  





Latest Threads
Call multiple function in...
by warcooft
4 minutes ago
Call to undefined functio...
by nanohe
1 hour ago
Query Builder Conditions ...
by kenjis
1 hour ago
Create a copy of file fro...
by Ege
7 hours ago
how to use set_select on ...
by kcs
9 hours ago
How to use Amazon PHP SDK...
by asimeou
Today, 10:53 AM
fatal logger emergency
by kenjis
Today, 03:39 AM
Array to HTML "Table"
by Bosborne
Today, 03:28 AM
Insert Batch Using Entity...
by warcooft
Today, 02:48 AM
SIngle quote on model sav...
by kenjis
Yesterday, 11:30 PM

Forum Statistics
» Members: 87,628
» Latest member: bangaloreescort1
» Forum threads: 77,648
» Forum posts: 376,387

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB