Welcome Guest, Not a member yet? Register   Sign In
  Controllers must have an index() function?
Posted by: El Forum - 05-04-2008, 10:23 PM - Replies (17)

[eluser]myerman[/eluser]
I just went through about 2 hours of line-by-line inquiry on a new controller that I added to an existing project. What I thought would be a very easy, very quick upgrade has turned into a lot of grief, but I think I might have stumbled on the solution.

Basically, I had a controller with two functions, create() and view(). There is no way for the user to edit or delete the category of data they are workign with, they can only simply create new one line notes and view them in detail.

well, I kept getting 500 Server Errors every time I linked to admin/attempts/create or admin/attempts/view. I checked for everything. Finally, out of sheer desperation, I renamed the view() function to index().....

....and everything worked just fine.

I just wanted to make double-sure as it appears to my muddled brain that all controllers MUST HAVE a index() function?
Anyone else have any thoughts on this?


  Converting DateTime Type to MM/DD/YYYY
Posted by: El Forum - 05-04-2008, 05:51 PM - Replies (16)

[eluser]Kesey[/eluser]
I've got a field in my database called "post_date" and it's of the type DateTime. When reading this field back and displaying it on my site, I want it to appear without the timestamp.

I'm trying this:

Code:
<h3>&lt;?= date('M d', $row->post_date); ?&gt;</h3>

within this loop:

Code:
&lt;?php foreach($query->result() as $row): ?&gt;
        
        <h3>&lt;?=$row->post_title?&gt;</h3>
        <h3>&lt;?= date('M d', $row->post_date); ?&gt;</h3>
        <p>&lt;?=$row->post_content?&gt;</p>
        <hr>        
    &lt;?php endforeach; ?&gt;

And I'm getting the error:
Message: A non well formed numeric value encountered

But it's also printing Dec 31 (I'm expecting May 3).

Any help would be appreciated. Thanks.


  How do you print all config vars to screen?
Posted by: El Forum - 05-04-2008, 05:35 PM - Replies (8)

[eluser]codex[/eluser]
I accidentally did it a few times, but I can't remember what it was. Something like print_r($config) (but that's obviously isn't working).

Also, is it possible to add config vars to the array without placing them in config files?
edit: yes, with $this->config->set_item('item_name', 'item_value');


  Showing database connection parameters
Posted by: El Forum - 05-04-2008, 03:02 PM - Replies (4)

[eluser]mdzwarts[/eluser]
I want to retrieve information about the database i've connected, to inform the user which database they are using right now. I have a custom class for my standard output components from which I want to collect this info. How do I do this, properly?

I've tried out:

Code:
$LIB =& get_instance();
$LIB->$db['default']['database'];
and:

Code:
$db['default']['database'];

and:

Code:
config_item('database')

..but no such luck. It would seem to me none of the above should actually work, but I'm fairly new to both php and code igniter.Reason I want to be able to display, is that we will be using multiple environments, and making sure by visual check is a good way to know if we are editing the right database.


  Can _output function within a controller load views?
Posted by: El Forum - 05-04-2008, 02:20 PM - Replies (9)

[eluser]inktri[/eluser]

Code:
function _output($output)
    {        
        $this->load->view('header_view');
        echo $output;
        $this->load->view('footer_view');
    }

for some reason only the $output (and not the header/footer) is being outputted for the controller. If I were to move the $this->load->view('header_view') function into the controller's constructor, the header loads properly.

Anybody know what's wrong? I've also tried
Code:
echo $this->load->view('header_view');


  re-routing images paths
Posted by: El Forum - 05-04-2008, 10:25 AM - Replies (8)

[eluser]AtlantixMedia[/eluser]
Hello,

can anyone tell me what's wrong with this re-routing rule?

$route['img/(general|bg|btn|logo)/(.*)'] = "system/application/images/$1/$2";

so that a url like this www.domain.com/img/general/test.gif

should be re-routed to www.domain.com/system/application/images/general/test.gif

it's not working as expected. thanks!!!


  FORUM BUG!
Posted by: El Forum - 05-04-2008, 10:22 AM - Replies (5)

[eluser]Gewa[/eluser]
HI, Have you tried to click on Fast Reply on Reply when you come to this forum from the notification email?
try it, you will understand what is the bug....


  Database Query Problem
Posted by: El Forum - 05-04-2008, 04:57 AM - Replies (2)

[eluser]Gewa[/eluser]
Hi I have in my database fields 'id','alias', 'de', 'en', 'ru' for category section.


So using URI Language Identifier, i get the current language, and now I want to get the right data and display them so i make


Code:
$query = $this->db->query("SELECT `$lang` FROM `cats` ");

foreach ($query->result_array() as $row)
{
   echo $row[$lang];
  
}


But its not working. Which is the best way, when you have lets say more than 1 listings and you should display them depending on $lang ?


  Variables are not transmitted to view? Validation not work.
Posted by: El Forum - 05-04-2008, 04:52 AM - Replies (7)

[eluser]v33s[/eluser]
Hi all. It`s my method in Controller:

Code:
function news($param = null)
{
if($param == 'edit')
            {
                $query = $this->sa->_editNewsById($this->uri->segment(4));
                foreach ($query->result() as $row)
                {
                    $resarray['title'] = $row->title;
                    $resarray['excerpt'] = $row->excerpt;
                    $resarray['content'] = $row->content;
                }
                

                $rules['title']   = 'required|max_length[40]';
                $rules['excerpt'] = 'required|max_length[255]';
                $rules['content'] = 'required';
                $this->validation->set_rules($rules);
                $this->validation->set_error_delimiters('<font color="red">', '</font>');

                if ($this->validation->run() == FALSE)
                {
                    $this->load->view('backend/sp_backend_news_edit', $resarray);
                }
                else
                {
                    $this->sa->_updateNews(
                        $this->uri->segment(4),
                        $this->input->post('title'),
                        $this->input->post('excerpt'),
                        $this->input->post('content'));
                    $this->load->view('backend/sp_backend_news_edit_success');
                }
            }
}

And this is my view:

Code:
&lt;?php
echo form_open('backend/news/edit');
echo form_label('Title:', 'title');
echo '<br />';
echo '<h6>'.$this->validation->title_error.'</h6>';
echo form_input(array('name' => 'title', 'value' => $title, 'maxlength' => 50, 'style' => 'width:34%'));
echo '<br />';
echo form_label('Excerpt:', 'excerpt');
echo '<br />';
echo '<h6>'.$this->validation->excerpt_error.'</h6>';
echo form_textarea(array('name' => 'excerpt', 'value' => $excerpt, 'rows' => 6, 'cols' => 35));
echo '<br />';
echo form_label('Content:', 'content');
echo '<br />';
echo '<h6>'.$this->validation->content_error.'</h6>';
echo form_textarea(array('name' => 'content', 'value' => $content, 'rows' => 12, 'cols' => 70));
echo '<br /><br />';
echo form_submit('submit', 'Sumbit');
echo form_close();

?&gt;
This code above are getting news from database (by ActiveRecords) and putting it into form that user can edit these values. There arent any errors, but if I submit form without one notfilled field, then I get errors:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: resarray

Filename: controllers/backend.php

Line Number: 205

And below after each field:

Quote:Severity: Notice

Message: Undefined variable: title ->> this variable is changing each field

Filename: backend/sp_backend_news_edit.php

Line Number: 227


Can someone explain me how to repair it?
I will be very thankfull Wink


  Another subdomain question
Posted by: El Forum - 05-04-2008, 03:16 AM - Replies (3)

[eluser]Fatih[/eluser]
Dears,

I have searched forum about multiple domain and subdomain names but I couldn't answer of my these problems.

I want to use one CI and my subdomain names will be input for my database. Please find an example:

Code:
http://mytopic.example.com/item/myitem

In this url, mytopic is a variable in my database which is pointed out to a theme. When item.php controller get this mytopic variable, item application will be run on this specified theme.

How can I solve it?


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

Username
  

Password
  





Latest Threads
tool bar not showing
by Luiz Marin
2 hours ago
Tool bar not showing
by Luiz Marin
2 hours ago
curl + response body
by InsiteFX
3 hours ago
AbuseIPDB Module
by InsiteFX
3 hours ago
Heads up for users using ...
by davis.lasis
Yesterday, 12:54 PM
The Hidden Cost of “Innov...
by fcoder
Yesterday, 03:11 AM
Validation does not appea...
by grimpirate
07-01-2025, 01:55 PM
Block IP addresses of bad...
by grimpirate
07-01-2025, 01:47 PM
Override Router
by grimpirate
07-01-2025, 01:30 PM
CodeIgniter.com - Report ...
by Vikas Mehta
06-30-2025, 10:30 AM

Forum Statistics
» Members: 154,512
» Latest member: allincollections
» Forum threads: 78,437
» Forum posts: 379,718

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB