Welcome Guest, Not a member yet? Register   Sign In
  Function that checks if a segment key exists ?
Posted by: El Forum - 10-12-2007, 02:12 AM - No Replies

[eluser]starbbs[/eluser]
Call me stupid but i need a function that simply returns the key if this key exists inside the URI class. I cannot seem to fin it. Let me explain:

Code:
/**
*   This returns true, even is the segment does NOT exist. Example:
*
*    $segment = array( 1 => 'cpanel',
*                      2 => 'admin',
*                      3 => 'module',
*                      4 => 'user',
*                      5 => '44');
*/

  // In my code, i use this to get the value:
  $segVal = $this->uri->segment(6, 0);

  // If all goes well, $segVal contains FALSE. but when i do:
  $segVal = (is_numeric($this->uri->segment(6, 0)) ? TRUE : FALSE;

  // Now segVal contains TRUE !

So, i was thinking that there might be a function, in where i can check for a key directly. But i cannot find this function. I created my own function. Maybe someone can think of a faster way:

Code:
// $name = the name of the segment you want to check
    // $return_index = When set to true, it returns the index of $name
    //                 When set to false, it returns $name when found
    // result: when found, the name or it's key, when nothing is found, it returns false
    
    function nsegment($name, $return_index = FALSE )
    {          
       if( in_array( $name, array_values($this->router->segments)))
       {
            foreach($this->router->segments as $segmentidx => $value ) {
                if($name == $value) {
                 if($return_index){
                  return $segmentidx;
                  }else return $value;
                }
            }
       }else
         return FALSE;
    }
     /* $cpanelidx contains '3' */
    $cpanelidx = $this->CI->uri->segmentn('module', TRUE);  
  
    /* $cpanel contains 'module' */
    $cpanel = $this->uri->nsegment('module');

If you have any suggestion for my problem, please reply!

Thnks @


  question about active records / db
Posted by: El Forum - 10-12-2007, 01:54 AM - No Replies

[eluser]Unknown[/eluser]
Hi.

I want to know how do I get the sql string what was generated by active records class.
For example, I have this code:
$this->db->select('*');
$this->db->where('id',3);
$this->db->where('name','test');
$this->db->from('my_table');

$query=$this->db->get();

The class generates something like
"select * from my_table where id=3 and name='test'"

How do I get this sql string ?


Thanks


  best way to create links
Posted by: El Forum - 10-12-2007, 01:13 AM - No Replies

[eluser]charlie spider[/eluser]
Hi everybody, just downloaded ci yesterday. Have only been programming for about 6 months or so using PHP, MySQL and CSS, but want to be able to better reuse code etc.

ci looks great

Just started to develop a new site and wanted to fish for peoples opinions regarding the best way to create links for the site's navigation using ci. i'm totally new to MVC and prefer to do things properly right from the start.

should i create the full link structure first:
ie: <a href="www.mysite.com/index.php">home page</a>
then feed that into an array and pass it to my view page ?

or should i feed the separate pieces into separate arrays (or a multidimensional array) and then assemble the pieces in my view ?

i'm thinking the first way seems to make the most sense.

And secondly, when using the URL Helper, i understand how site_url() works and i understand how auto_link() works, but is there any way to input the text portion for the link. Using my example above:
<a href="www.mysite.com/index.php">home page</a>
How do i input "home page" into site_url() and/or auto_link() ???

if it wasn't midnight already i would prolly just figure this out myself, but i'm tired and want to cut corners and have smart people tell me what's best.

Any ingenious insights into ci and creating links would be greatly appreciated.

Thanks in advance.


  shopping for a scalable php framework
Posted by: El Forum - 10-11-2007, 11:42 PM - No Replies

[eluser]edoornav[/eluser]
Hi,

I am looking for a lightweight php framework in which to build a fast and scalable web application. I've done the tutorials and code igniter seems to be what I'm looking for. My problem is that I'm getting some bad results from simple performance tests. I installed MAMP and ran apache bench on a simple static file containing 'Hello World':

ab -n 1000 -c 5 http://localhost:8888/index.html -> 350 requests per second (my laptop is slow)

Next I ran it on a php file containing '&lt;?php print "hello world" ?&gt;':

ab -n 1000 -c 5 http://localhost:8888/test.php -> 250 requests per second

Next I installed code igniter, and did the blog tutorial up to the point where it just prints "hello world":

ab -n 1000 -c 5 http://localhost:8888/index.php/blog -> 20 requests per second!

Using a view and displaying a single db row gets me down to 15 requests per second. Doing the same thing in a simple script gives me 150 rps.

This seems too high a penalty to pay for MVC. Is this a typical result or might there be something wrong with my configuration? I'm otherwise really impressed with this framework and would definitely use it on a smaller project.

Thanks in advance for any help.

~rvr


  Reset of Validation possible?
Posted by: El Forum - 10-11-2007, 10:51 PM - No Replies

[eluser]esbium[/eluser]
Hey everyone,

I have a form that submits to a controller, gets validated and then inserts the data into the database. All of that works fine. However, once all of that is done, I want to re-display the same form so the user can enter another record. When I do this, the old values from the last submit remain in the form. I do not want to use a redirect here.

I have tried creating a new instance of CI_Validation after a successful submit in hopes that it would reset all the values that were stored in it but that doesn't work.

Basically, the calls to $validation->someFormField return the last value from the submit. I know that this is great when there are errors, but I need to clear them if there are no errors!

Please help and thanks in advance!


  400 Errors
Posted by: El Forum - 10-11-2007, 10:40 PM - No Replies

[eluser]CI Lee[/eluser]
Hey all,

Keep getting a 400 error

Quote:Bad Request

Your browser sent a request that this server could not understand.

This is my .htaccess file
Code:
AddHandler php5-script .php

Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php?/$1 [L]

Anyone see anything that maybe causing those errors? They are sporadic browser/client independent...

-Lee


  image dowloads on clicking a link?
Posted by: El Forum - 10-11-2007, 06:51 PM - No Replies

[eluser]megabyte[/eluser]
You know when you have a zip file and you attach it to a link it downloads to your computer when you click it.


Is it possible to do this with an image?


  Big problem with arrays and checkboxes
Posted by: El Forum - 10-11-2007, 06:41 PM - No Replies

[eluser]Référencement Google[/eluser]
Hi,

I am facing a big problem to repopulate checkboxes group from a DB.
Here are the situations:

- The checkbox group can be empty the first time, because we have to add the user selection to the DB
- The checkboxes can be selected according to the DB, for exemple in a editing case
- Finally, we have to keep the choice of the user while posting the form for validation.

So here is my actual code:

Code:
function DB_checkBoxes($data, $fieldName, $values = array())
{
    $CI =& get_instance();
    
    $html = '';
    $selected = '';
                  
    foreach($data as $item)
    {
        if (!empty($_POST))
        {
           $selected = $CI->validation->set_checkbox($fieldName, $item->word_ID);
        }
            
        foreach ($values as $value)
        {
            if ($value->word_ID === $item->word_ID)
            {
               $selected = ' checked="checked"';                  
            }
        }
                
        $html .= "    <label class=\"checkbox\">";
        $html .= "&lt;input type=\"checkbox\" name=\"".$fieldName."[]\" value=\"".$item-&gt;word_ID."\"".$selected." /> ".$item->word;
        $html .= "</label>\n";            
    }
        
    return $html;
}

Code explaination:
$data is an array containing all the checkboxes
$fieldName is the name of the input, in my casse it will be for exemple choices[]
$values is the array coming from the DB with the checked checkboxes that was saved by the user

I don't know if somebody can help me, really I tryed almost all day about that and can't find the solution!


  Starting a new project
Posted by: El Forum - 10-11-2007, 05:09 PM - No Replies

[eluser]bosco500[/eluser]
First, I have to say this is the most complete and easy to understand programming "language" I've ever come across. I realize its not a full blown language, but you get the gist. Whoever created codeignitor needs a pat on the back. Good work guy.

I've seen a huge null in the market for invoicing/job costing/accounting software for the line of work I'm in. There are tons of softwares out there, but this is sort of a special market that needs special equations built into its software. There are a few desktop apps, but absolutely no web apps. That being said, I'm absolutely new to using any php framework. This will be a fairly large app, so I would like to get started on the right foot.

When dealing with "controllers", how often do you use a new controller? Do you use a controller for each "section" of your program? I realize this is a very vauge question, but I don't know how else to ask. In an invoicing program, would have have a controller for customer, items, users, etc... or would you use one controller? I was thinking break the controllers as small as possible, to allow for easy user authentication/privileges. Am I correct?

Also, I realize everyone programs different, I'm just trying to get some ideas. I've done some fairly large size DBase programs, but this is a different animal Smile

Thanks for any ideas!


  Any JavaScript/AJAX library to resize an image for upload?
Posted by: El Forum - 10-11-2007, 04:59 PM - No Replies

[eluser]Optimus Prime[/eluser]
Hi!

I want to know if somebody knows about a JavaScript / Ajax Library to resize and crop a image on the client side?

I'm trying to add one to upload images resized instead to resize on the server's side because the images to upload are to larger and heavy. If is possible, to crop an area of the image and upload it.

There is a library like this on the net? Commercial versions are welcome , but i prefer Open-Source/GNU/GPL/LGPL.


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

Username
  

Password
  





Latest Threads
hot-reload side effects s...
by PaulC
8 hours ago
CodeIgniter.com - Report ...
by Harry Lyre
9 hours ago
Setting baseURL in Regist...
by michalsn
Today, 12:09 AM
Update from 4.6.0 to 4.6....
by FlavioSuar
Yesterday, 04:17 AM
Sessions old files are de...
by InsiteFX
05-12-2025, 10:30 PM
Ajax post failing with Ty...
by PaulC
05-12-2025, 12:23 AM
intermittent smtp failure...
by InsiteFX
05-11-2025, 11:30 PM
MVC vs MVCS vs CodeIgnite...
by FlavioSuar
05-10-2025, 10:33 AM
CodeIgniter Shield 1.0.0 ...
by timesprayer
05-10-2025, 05:22 AM
Website Traffic Drop Afte...
by InsiteFX
05-10-2025, 04:23 AM

Forum Statistics
» Members: 145,988
» Latest member: yuristbfl
» Forum threads: 78,389
» Forum posts: 379,450

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB