Welcome Guest, Not a member yet? Register   Sign In
  Custom 404 controller like any other controller
Posted by: El Forum - 06-23-2007, 08:35 AM - No Replies

[eluser]Henrik Pejer[/eluser]
Hello fellow CI code crunchers!

I decided to start my venture down the CI-path with a little fix for, as I'd call it, complete custom 404 controller page.

I searched the forum for how I should make a custom 404-page. It seemed like I should extend the Exceptions-class. The only problem is that the 404-event triggers before all the base classes are loaded: I have no controller, database etc.

I think the reason for this is based on security: not letting an ill typed URL somehow get run by CI as a normal controller.

But I realized that by extending not the Exceptions class but rather the Router-class, I was able to 'fool' CI to use one of my own controller, and let the system load as normal.

All I did was copy the '_validate_segments'-function and slightly modify it to return the custom controller I wanted to use as 404-page. My custom 404-controller is called 'custom404controller' and located in my application/controllers/-folder, like any other controller.

A word of advice: before you use this, test it thoroughly! Also make sure that by using this way of handling 404-errors, you do not compromise the security of you application. Also,this is for version 1.5.3 of CI.

This is the extension that seemed to do the trick:

class MY_Router extends CI_Router{
    function MY_Router(){
    function _validate_segments($segments)


        // Does the requested controller exist in the root folder?

        if (file_exists(APPPATH.'controllers/'.$segments[0].EXT))


            return $segments;


        // Is the controller in a sub-folder?

        if (is_dir(APPPATH.'controllers/'.$segments[0]))


            // Set the directory and remove it from the segment array


            $segments = array_slice($segments, 1);


            if (count($segments) > 0)


                // Does the requested controller exist in the sub-folder?

                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))

                    # HENRIK PEJER MOD: commented out the line below, added the line below that

                    return $this->custom_404();








                // Does the default controller exist in the sub-folder?

                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))


                    $this->directory = '';

                    return array();




            return $segments;



        // Can't find the requested controller...
        # HENRIK PEJER MOD: commented out the line below, added the line below that
        return $this->custom_404();

    function custom_404(){
        # return an array with the name of the controller we want as the 404-handler...
        return array('custom404controller');

Any advice, tips or concerns regarding the code above would be very interesting to hear.

Take care and happy CI:ing!

  alpha, xss_clean and i18n in CI
Posted by: El Forum - 06-23-2007, 04:16 AM - No Replies

I have been trying to resolve two CI issues:

Validation.php -> all TRUE alpha-based functions are ASCII only
Input.php -> xss_clean silently returns an empty $_POST value if entry string is not ASCII

Both problems are already documented in the forums. Unless hacked, these core functions are not usable for anyone outside the basic ASCII geography (not even the ISO-8859-1 folks).

I have attempted, as a start, to change the locale and alter the relevant regexp patterns in Validation.php, but it fails. It seems, to me, that PCRE does not support the extended ASCII charsets despite first checking and then setting the correct locale. I hope someone may be able to assist with this to help resolve these issues. Some example snippets:

CI Validation.php alpha():

function alpha($str)
        return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE;

Checking locale (varies according to your region, of course):
$loc_no = setlocale(LC_ALL, 'no_no', 'no_NO', 'nb_NO','nb_NO.ISO-8859-1','no_NO.ISO-88591');
echo "Preferred locale on this system is '$loc_no'";

Setting tested locale:
setlocale(LC_ALL, 'no_no');

Replacement pattern:
function alpha($str)
        return ( ! preg_match("/^([a-zæøåÆØÅ])+$/i", $str)) ? FALSE : TRUE;

Validation strings containing the extra chars still return FALSE. Then there's the bigger xss_clean issue. Has anyone resolved these i18n issues with CI, or just written their own callbacks instead (perhaps a better approach than always hacking the core?), or just turned off those rules and hoped for the best?

  Basic Question for a newbie
Posted by: El Forum - 06-23-2007, 03:03 AM - No Replies

Hello everyone,
i am totally new to CI.
I watched the video tutorials, which are impressive. doing the tutorials step by step on my own server seem to get me some problems already tho.
when i started to extend my controller with a db-query

$data['query'] = $this->db->get('user');

it results in Fatal error: Call to a member function on a non-object .

now i havent made anything special at all, just following the video tutorial of "creating a blog in 20min". The scaffolding feature works nicely, tho if i try to connect on my own to the database it seems impossible to work. i was searching the forum already for over an hour to find a proper solution to my problem, but nothing seems to help.

linux server

  template parser attributes
Posted by: El Forum - 06-23-2007, 02:16 AM - No Replies

is available to add attributes to parse template tag link ExpressionEngine
For example

{link slug='your slug here'}

  I think the code is correct. But.........
Posted by: El Forum - 06-22-2007, 11:12 PM - No Replies

Here is my code in processing file upload :

class Ungxu extends Controller
  function Ungxu()
function index()
       $this->load->view('ungxu', array('error' => ' ' ));// pass error argument
       // attach file upload (if have)
function doUpload()
        $config['upload_path'] = '/uploads/ungxu/';
        $config['allowed_types'] = 'doc|txt|rar';
        $config['max_size']    = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $this->load->library('upload', $config);
            if ( ! $this->upload->do_upload())
                $error = array('error' => $this->upload->display_errors());
                $data['content'] = $this->load->view('dangky', $error, true);
                $upload_data = $this->upload->data();
                $filename = $upload_data['file_name'];

and view:
    &lt;?=form_open_multipart('ungxu/doUpload'); ?&gt;

      <td style="width: 198px">
      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Tài liệu đính kèm</td>
      <td>&lt;input name="filename" type="file" id="filename" /&gt; (Tối đa 1MB)</td>
    <td align="center" colspan="2">
     &lt;input type="submit" name="submit" value="Gửi" id="send" style="width:70px;"
&lt;input type="reset" value="Làm lại" /&gt;                            
My idea is if a visitor upload a file and webpages will automatically attach file to send mail. But when i try it, an error generated:
Quote:An Error Was Encountered
Unable to load the requested language file: language/upload_lang.php
My code have some problems? Please tell me how can resolve it? Thank you..

  Interfacing to a Windows web service advice
Posted by: El Forum - 06-22-2007, 09:36 PM - No Replies

[eluser]Pete Smith[/eluser]
Forgive me if this has been discussed. Some of the terms are used in so many ways that I'm finding searching to be problematic.

I'm building a shopping cart that has to authorize a credit card against a pre-determined Web Payment Service (EFSNet, to be precise). I have 3 options: SOAP, XML, or Name/Value Pairs. The server I'm going to be running on has PHP 4, so I can't use PHP's SOAP Extension. I've heard of nuSOAP but I don't know if it's still being developed and I'm not sure its secure enough to be sending credit card data back and forth with. Thoughts on that?

XML seems promising and I was wondering if there's a way to somehow use the XML-RPC Class to send and receive XML files, perhaps by modifying the code somehow? The only example EFSNet provides (they're clearly a MS shop) uses COM:

Quote:This sample demonstrates an XML POST using the XMLHttpRequest object
found in Microsoft® XML Parser (MSXML), version 3.0 or higher. The example
provided is written in Visual Basic; however, this can be used from any language
that supports Component Object Model (COM) objects.

DOMDocument XML POST Example
‘ Note: Add project reference to Microsoft XML, Ver 3.0 or 4.0
Dim sXML As String
Dim iDocument As New MSXML2.DOMDocument
Dim iHttp As New MSXML2.XMLHTTP30
sXML = "<Request StoreID='myStoreID'" & _
" StoreKey='myStoreKey'" & _
" ApplicationID='EFSnet samples 1.0'>" & _
"<SystemCheck/>" & _
iHttp.Open "POST", "https://test.testserver.com/test.dll",
iDocument.async = False
iDocument.loadXML sXML
iHttp.Send iDocument
MsgBox iHttp.responseText

Is there a clean way to send/receive XML using CI?

Last is the CGI, Name/Value pairs option which feels like it'd be messy, but maybe CI helpers could make it easier? Is an https GET secure enough that I should be comfortable doing it? Here's what the spec guide has to say:
Quote:Example of Name/Value Pair Send (HTTPS GET)

Example of Name/Value Pair Reply

I'm sorry if this all sounds a little vague. I've been researching myself into circles to the point where its all a blur. I just need a kick in the butt to send me looking in the right direction. (This is the first time I've ever done anything like this in PHP, let alone in CI. I could do it in Tcl! Much good that does me these days... Smile )

  Troubles with PostgreSQL
Posted by: El Forum - 06-22-2007, 08:53 PM - No Replies

Hi, all. I'm not long ago begin to use CodeIgniter, it's nice and light for understanding framework.
But when I face to some troubles when I try to work with postgresql.
I edited database.php as needed and when loading database library thereis no errors i.e. connecting and selecting database passed successfully, but such construction

$query = $this->db->query("SELECT * FROM some_table");
echo "<pre>";
echo "</pre>";
return empty result_array, although some_table not empty. I'm use latest version of codeigniter and version of postgresql sever is 8.0
Doe's enybody know reason of my trouble.

  Sessions....... :(
Posted by: El Forum - 06-22-2007, 07:33 PM - No Replies

I am taking a stab at CI, and I have hit a bit of a wall. I created a user login function in my user controller, and it works dandy right up until I navigate away from the landing after sucessfully authenticating. My sessions disapear.

I will be using sessions to secure pages, so if your session user id value is not populated then you will be redirected to log in. Anyhow here is what I have.

function login()


            $query = $this->db->query("SELECT * FROM users WHERE username = '".$_POST['username']."' and password = '".md5($_POST['password'])."'");
        if($query->num_rows() > 0){
            //return true;
            $status = "0";
             foreach ($query->result() as $row)
                 $username = $row->username;
                 $id = $row->id;
            $sid = array('id' => $id);
            $data['goodz'] = $this->session->userdata('id');
            $data['status'] = $status;
                else {
                    $status = "1";
                    $data['status'] = $status;
                    $data['goodz'] = $this->session->userdata('id');

  IIS + CI Problems!
Posted by: El Forum - 06-22-2007, 06:49 PM - No Replies

Hi there,
Recently I started to test out my CI products in IIS Server environment, and I noticed this problem. And I really hope somebody can help me solve this problem Smile.

If I visit CI Application homepage like (http://localhost/ci/) by not modifying config.php file, I get 404 Page Not found error.

Then if I change $config['uri_protocol'] = "AUTO"; to $config['uri_protocol'] = "PATH_INFO";

The welcome page loads just fine Smile.

However, if I visit http://localhost/ci/index.php/welcome, it doesn't work Sad. The error HTTP Error 502.2 - Bad Gateway by IIS.

Any ideas on how to fix this other than using query strings? I LOVE FRIENDLY URLS! Sad.

  How to effectively search in the userguide?
Posted by: El Forum - 06-22-2007, 01:05 PM - No Replies

Hi all,

As a n00b to CI (and frameworks in general) I'm relying heavily on the (excellent) user guide. However, using it search function will almost always give me just 1 result in Google and that one is the change log. That's not helping me a lot, so is there another way of searching the user guide more effectively? (Or should I built a CI app for it? ;-) )

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



Latest Threads
trying to run function ju...
by richb201
1 hour ago
Help Needed with Document...
by kilishan
2 hours ago
500 Internal Server Error...
by ikesela
3 hours ago
Codeigniter 4 set_cookie ...
by ikesela
3 hours ago
Mythauth - update passwor...
by ikesela
3 hours ago
CIv4 Call to a member fun...
by ikesela
3 hours ago
cara mengatasi codeignite...
by adunk
4 hours ago
Need help connecting to A...
by craig
7 hours ago
CLI in command line no re...
by superior
Yesterday, 06:40 AM
curlrequest not updating ...
by chakycool
Yesterday, 05:28 AM

Forum Statistics
» Members: 24,753
» Latest member: gangathara
» Forum threads: 73,633
» Forum posts: 359,401

Full Statistics

Search Forums

(Advanced Search)

Theme © iAndrew 2016 - Forum software by © MyBB