Welcome Guest, Not a member yet? Register   Sign In
  CI 1.6, Small bug in database class
Posted by: El Forum - 02-17-2008, 03:33 AM - Replies (2)

[eluser]Unknown[/eluser]
The orderby() function seems forgot to add table prefix to the sql query string.
For example, all my database table has a prefix t2:

Code:
$this->db->join('users', 'messages.user_id = users.id', 'left outer');                                                              
  $this->db->orderby('messages.id', 'desc');                                                                                      
  $query = $this->db->get('messages');
Got the following error:
Quote: An Error Was Encountered
Error Number: 1054
Unknown column 'loginlogs.id' in 'order clause'
SELECT * FROM (`t2_messages`) LEFT OUTER JOIN `t2_users` ON t2_messages.user_id = t2_users.id ORDER BY messages.id


  HTTPS, downloading a file fails in IE
Posted by: El Forum - 02-17-2008, 03:09 AM - Replies (1)

[eluser]JoseG[/eluser]
Hi,

I have a problem in one site that uses HTTPS. Everything works fine, but when I try to download a file (a PDF), IE complains with the message:

"Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later."

After some investigation it seems to be a bug in Internet Explorer (http://support.microsoft.com/kb/316431)

It seems that the Cache related stuff on the Header directives could be causing the trouble. I've removed them from my download code with no luck.

I'd appreciate any help you could provide.

Thanks in advance,

Jose


  CI v1.6.1 Core change "feature"?!?
Posted by: El Forum - 02-17-2008, 01:07 AM - Replies (6)

[eluser]Michael;[/eluser]
Please excuse the slight hostility... I don't mean to be ... really.

From the Change log:

Quote:# Added $_SERVER, $_FILES, $_ENV, and $_SESSION to sanitization of globals.

Seriously?! $_SESSION ... sanitized?!?!

Now, I understand, to some degree, removing $_GET ... but $_SESSION!?!? Come on... CI Sessions only allow for 4kb of data ... that is just fracking insane!

Can someone *PLEASE* offer up some explanation on this one?


  htaccess causes loss of stylesheet
Posted by: El Forum - 02-17-2008, 01:01 AM - Replies (6)

[eluser]Michael;[/eluser]
For some reason when I try to use the CI Guide version of an .htaccess to remove 'index.php' from my urls I lose all reference to my style sheet in my views:

from my template:
<link href="<?=base_url()?>files/css/default.css" rel="stylesheet" type="text/css" />

I do not have 'index.php' in the base url config, as I missing something here?

Thanks!


  DB_active_rec.php, function: select(), issue: cannot use MySQL IF function (not construct) + more.
Posted by: El Forum - 02-17-2008, 12:56 AM - Replies (2)

[eluser]MPress[/eluser]
You cannot use the MySQL IF function within the string argument for the select active-record function. This is because it tries to reconcile the values by exploding on a ','. Although, I somehow remember this not being an issue previously... Anyways, the IF function has the syntax of: IF({cond. is met}, {return this}, {otherwise this}).

Update:

As well, the new automatic backquote feature of AR functions fails on this kind of thing: FORMAT(something, 2) since we get FORMAT(`something`, `2`). 2 must be numeric and therefore cannot be enclosed in backquotes.

Here is a temporary workaround for the first issue. Simply escape special commas by doubling up (',,'). Follow $comma_fix.

Code:
function select($select = '*', $protect_identifiers = TRUE, $comma_fix = FALSE)
    {
        if (is_string($select))
        {
            if($comma_fix && strpos($select, ',,') !== FALSE){

                $select = str_replace(',,', '?~', $select);
            }

            $select = explode(',', $select);
        }

        foreach ($select as $val)
        {
            $val = trim($val);

            if($comma_fix && strpos($val, '?~') !== FALSE){

                $val = str_replace('?~', ',', $val);
            }

            if ($val != '*' && $protect_identifiers !== FALSE)
            {
                if (strpos($val, '.') !== FALSE)
                {
                    $val = $this->dbprefix.$val;
                }
                else
                {
                    $val = $this->_protect_identifiers($val);
                }
            }

            if ($val != '')
            {
                $this->ar_select[] = $val;
                if ($this->ar_caching === TRUE)
                {
                    $this->ar_cache_select[] = $val;
                }
            }
        }
        return $this;
    }


  CI + mootools + ajax (actually works)
Posted by: El Forum - 02-16-2008, 11:09 PM - No Replies

[eluser]mr_coffee[/eluser]
Yeah I saw some answers for this floating around. But none suited very SIMPLE needs. I found the following on some post on something or another but lack the patience to look it up again. The poster mention "extending" the input library with the following:

Code:
function isAjax() {
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest");
    }

Which to me translated as "add this to the bottom of ci/libraries/input.php and re-upload".

Now in your controllers, you will now have the option to say if isAjax() do this... otherwise do something else. I'd say that something else is the default behavior which is to load the view for each item on the page... whereas if it was an Ajax call... instead of "viewing" navigation, the page layout, the title, etc... you're just "viewing" the one element on the page to be updated. I'll give you this example of actual code I am using:

Code:
function work() {
        if($this->input->isAjax()) {
            $this->load->view('work');            
        } else {
            $data['title'] = "Where I live and work";
            $this->load->view('title',$data);
            $this->load->view('scripts');
            $this->load->view('header',$data);
            $this->load->view('navigation');
            $this->load->view('work');
            $this->load->view('footer');
        }
    }

This works perfectly and as expected. I'll need to - however - add some javascript to update the <title> of the page and the text on the page that shows the title (fourth line in the else portion). Such a SIMPLE answer... reading all these "answers" about trying to re-invent the wheel was giving me a headache. Please repost this enough times that those posts will be trumped in the search engine by this easy working answer.

Contention: you CANNOT USE the safe_email() function on an ajax requested page. It utilizes the javascript d0cument.wr1t3 and that will break everything. Expect an "Operation Aborted" error thrown by IE and a white page that never finishes load in any other browser. Anyway, it will be messy. You could set evalScripts to false and kill the error, but you won't see your e-mail link either. There may be more things you can't use, but that's the one I noticed right away. NO DOCUMENT.WRITEs!


Now for my question: why is it that Opera doesn't display Ajax loaded content inside the specified div? This isn't a CI question, I was just hoping someone had a work-around for that, I'm coming up empty everywhere else. (ps... downloaded the DOM snapshot plugin for Opera: the code is perfect. Tells me the visual rendering should match up, but visually, my ajax requested pages are not displaying within the div I specified, even though by the DOM snapshot: they should be)

Now for my CI question: has anyone successfully written some sort of helper/library/class/ANYTHING that would handle an Ajax "history". Like along with my "$this->load->view('work');" I should have a line saying "$this->history->updateaddressbar('info/work'); $this->history->addclick();" or something like that so that basic back/forward/bookmark/reload functions would be restored. I was playing with something that worked "ok" in mootools, but it was kind of a hassle. I'm not really wanting to test what happens if I start adding hashes to the address bar either while CI is running. I don't expect positive results. I also already know the aforementioned history manager crashed and burned in Opera as well as the basic ajax calls. Strange... I was under the impression Opera allowed MORE things to work, not fewer. Whatever. If you're aware of a history addon thing, I'd like to know.

thanks much.


  Reading/Parsing Directories and Files
Posted by: El Forum - 02-16-2008, 09:27 PM - Replies (3)

[eluser]pgsjoe[/eluser]
Hate to rely on the message board, so I apologize. Here's the deal though. I have a directory called 'Photos' inside of photos are 'Category1', 'Category2', etc.

First thing I want to do is get an array of the directories inside 'Photos' so I can put those into a dropdown list. Second, I want to be able to get a list of files from inside the category chosen, to put inside their own dropdown list.

Idea being, the client would create directories and upload photos using an FTP client. Then, associate those files to Title, Alt tags and Dates using a CI form. The form would allow the person to enter previous info, then attach the file information (directory & filename) to it and upload it to the database.

The client is a photographer, and since they have access to an FTP I don't really see a form uploader as being entirely necessary. So, I thought this might be the easiest way. So any help with getting it to work, or suggestions on a better, hopefully not TOO complicate way would be awesome.

This is the first full client project I'm trying out CI on and am damn excited to be jumping in. Hence, sitting home on a Saturday night coding. Thanks in advance.


  Godaddy Error - No input file specified.
Posted by: El Forum - 02-16-2008, 09:07 PM - Replies (8)

[eluser]Unknown[/eluser]
Searched forums, tried everything, couldn't get anything to work. My host is godaddy. When I go to my site.com/index.php/category/ and it just says No input file specified. How do i fix this?

Thanks.


  Validating and prepping...
Posted by: El Forum - 02-16-2008, 08:45 PM - Replies (7)

[eluser]~Chris~[/eluser]
This may sound like a dumb question. Im going over the validation class.

Code:
$rules['username'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
$rules['password'] = "trim|required|matches[passconf]|md5";
$rules['passconf'] = "trim|required";
$rules['email'] = "trim|required|valid_email";

Just like the user guide says it would, when there is an error the password is still re-filled into the form with its new md5 hash, instead of the password the user typed in.

It says to prep the data after its done validating, instead of all together.

So, can someone give me an example of how I would prep it. For example? do i just run the $this->validation->run() function a second time to handle the data prepping?

your help is appreciated.


  default request by extending Router
Posted by: El Forum - 02-16-2008, 08:30 PM - Replies (6)

[eluser]zauber[/eluser]
Hi, here's a small contribution that some might find useful.

I'm working on a really simple and sweet CMS with CodeIgniter, which handles pages that basically just have content and slugs (a string that only contains alphanumerics and underscores)

when you visit

Code:
http:://www.mysite.com/pages/read/some_slug

then the task of Pages->read($slug) would be to show the content of the page with slug 'some_slug'.

now... I wanted to be able to enter:

Code:
http:://www.mysite.com/some_slug


and get the same effect. But I wanted to do it in a way that it wouldn't disturb any other routes. (Simply adding a $route[:any] = "pages/read", didn't work.

I solved it by extending the Router class, and allowing another special $route index.

Heres the Router extension:
Code:
class MY_Router extends CI_Router{
    function _validate_segments($s){
        if (count($s)==1 && !file_exists(APPPATH.'controllers/'.$s[0].EXT)){
            if (isset($this->routes['default_query'])){
                $segments = explode("/",$this->routes['default_query']);
                $segments[] = $s[0];
                $this->set_class($segments[0]);
                $this->set_method($segments[1]);
                return $segments;
            }
            show_404();
        }
        else return parent::_validate_segments($s);
    }
}

The special $route index is 'default_query' and it work so that if you put in:

Code:
$route['default_query'] = "mycontroller/amethod"

then any requests like:

Code:
http://mysite.com/writesomethinghere

will execute as: MyController->amethod('writesomethinghere');

My questions are:

1) Is there a more direct 'built-in' way of achieving this that I have overlooked?
2) Does this punch any holes in security or break functionality in some way I have yet to notice?
3) Is this the most efficient (computing-wise) way of adding this feature, without hacking the Router class directly? I tried to avoid as much repetition of code in the Router class as possible, and adding as little new code as possible myself, but I'm not sure how well I succeeded.


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

Username
  

Password
  





Latest Threads
Getting supportedLocales ...
by kcs
3 hours ago
Codeigniter Shield Bannin...
by xsPurX
5 hours ago
Best way to create micros...
by InsiteFX
9 hours ago
Component help
by FlashMaster
11 hours ago
Show logo in email inbox
by WiParson
Today, 12:48 AM
Limiting Stack Trace Erro...
by byrallier
Yesterday, 02:21 PM
Bug with sessions CI 4.5....
by ALTITUDE_DEV
Yesterday, 01:36 PM
codeigniter 3.0.1 equiped...
by JustJohnQ
Yesterday, 10:05 AM
Display a custom error if...
by b126
Yesterday, 06:22 AM
Type error in SYSTEMPATH\...
by DXArc
Yesterday, 06:20 AM

Forum Statistics
» Members: 85,221
» Latest member: Easton900
» Forum threads: 77,575
» Forum posts: 375,964

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB