Welcome Guest, Not a member yet? Register   Sign In
  New Layout View Library Supporting Partial Views [Update 2]
Posted by: El Forum - 10-10-2007, 04:53 PM - No Replies

[eluser]Gyorgy Fekete[/eluser]
Hey, this is update 2 of my layout view library. You can check out the original library and what is all about here: http://ellislab.com/forums/viewthread/62366/

Update 2: It's partially rewritten code. Now supporting auto loading data variables in partial views. And is PHP5 compatible ONLY.

I will write down each method in detail:

clear()
Without any argument it resets the layout library.
If of one of these strings 'partials','datas','layout' then is resets the respective partials, data variables or layout parts.
Example:

Code:
$this->layout->clear();
$this->layout->clear('partials');
$this->layout->clear('datas');
$this->layout->clear('layout');

addPartial(arg1,arg2,arg3)
Adds a new partial view to the current layout.
arg1 = the name of the partial view (not the filename)
arg2 = the filename of the partial view (without the .php extension)
arg3 = optional data array to be passed to the partial view

addPartialData(arg1, arg2)
Adds data variables in form of an array to a partial view.
arg1 = the name of the partial view (not the filename)
arg2 = the data array to be passed to the partial view

addPartialLayout(arg1,arg2)
Adds a partial layout to the current layout.
arg1 = the name of the partial layout
arg2 = optional argument. The filename of the partial layout (without the .php extension). It can be set later with the setLayout() method.

Example:
Code:
$this->addPartialayout('header','partials/header_layout');
$this->header->addPartial('header_left','partials/header/header_left');

hasPartial(arg1)
Checks if the current layout has the specified partial view.
arg1 = the name of the partial view (not the filename)

hasData(arg1)
Checks if the current partial view has any data defined.
arg1 = the name of the partial view (not the filename)

getPartialType(arg1)
Returns the type of the specified partial view.
arg1 = the name of the partial view (not the filename)
returns: partial view, partial layout or NULL if the specified partial doesn't exists

getLayout()
Returns the filename of the current layout. Layouts doesn't have name. You only set the filename (without the .php extension)

setLayout(arg1)
Sets the current layout.
arg1 = the filename of the layout (without the .php extension)

view(arg1)
Render the layout.
arg1 = optional argument. Boolean, whether to render or return the layout.


Example of using this library:

Code:
$this->layout->clear();

$this->layout->addPartialLayout('header','test/header');
$this->layout->header->addPartial('bottom','test/bottom');

$this->layout->header->addPartialLayout('top','test/top');
$this->layout->header->top->addPartial('top_left','test/top_left');
$this->layout->header->top->addPartial('top_right','test/top_right');
        
$footer_data['custom_data'] = 'this is footer custom data';
$this->layout->addPartial('footer','test/footer',$footer_data);
$this->layout->setLayout('test/test_layout');
        
$this->layout->view();

You can set an auto loading configuration file. Just name it after the layout library filename and put it into your configs folder.

Example configuration file:
Code:
/*
reserved words are between ::
*/

$config[':partials:'] = array('header' => ':layout:','footer' => 'test/footer');

$config[':layoutfile:'] = 'test/test_layout';
$config[':datas:']['footer']['custom_data'] = 'this is footer custom data';


$config['header'][':layoutfile:'] = 'test/header';
$config['header'][':partials:'] = array('top' => ':layout:', 'bottom' => 'test/bottom');

$config['header']['top'][':layoutfile:'] = 'test/top';
$config['header']['top'][':partials:'] = array('top_left' => 'test/top_left', 'top_right' => 'test/top_right');

The word between :: are reserved words. It is self explanatory.

You can download a working example with the library included here. After downloading just extract the zip file into your application folder. And browse to test/configure_no or test/configure_yes controllers. The first doesn't auto load the configuration file the second auto loads it.

The link is: http://www.primalskill.com/layout_update2.zip


  CI is insecure with Register Globals enabled
Posted by: El Forum - 10-10-2007, 12:32 PM - No Replies

[eluser]Jon L[/eluser]
okay, pretty much everyone with half a brain is aware that Register Globals are *bad*, but for the people that still have it enabled on their webservers, installing CodeIgniter opens up possible security flaws.

An example url is the following that allows you to generate a javascript link on the application 404 error page

Quote:/system/application/errors/error_404.php?heading=Click%20the%20link&message;=<a%20href="[removed]alert('hi');">click%20me</a>


To fix this immediately, you can modify your .htaccess file, and add the following line (this works on most, but not all, servers):
Code:
php_flag register_globals 0


  Ubuntu Lamp server problems
Posted by: El Forum - 10-10-2007, 11:16 AM - No Replies

[eluser]Jamongkad[/eluser]
Hi all I recently purchased a Dell Inspiron laptop install with Ubuntu Feisty Fawn. Anyways I managed to install LAMP through sudo aptitude. I'm running the server now and I copy pasted a CI 1.5.4 into the var/www directory. To my surprise I get this error

Code:
Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0

Fatal error: Unknown: Failed opening required '/var/www/myapplication/index.php' (include_path='.:/usr/share/php:/usr/share/pear') in Unknown on line 0

What does this mean?


  Error in documentation (Inserting into a database by setting object variables)
Posted by: El Forum - 10-10-2007, 11:02 AM - No Replies

[eluser]tmcw[/eluser]
I'm following the user guide on a new project, and <a href="
http://ellislab.com/codeigniter/user-gui...odels.html">this page</a> has the syntax

Code:
function insert_entry()
    {
        $this->title   = $_POST['title'];
        $this->content = $_POST['content'];
        $this->date    = time();

        $this->db->insert('entries', $this);
    }

For inserting an entry. Using something very similar to that seems to try to insert all of the inherited properties of Model, and thus throws an error.

Code:
function insert_run()
    {
       // $this->date = $_POST['date'];
       // $this->tod = $_POST['tod'];
        $this->duration = $this->time_to_s($_POST['time_ms'], $_POST['time_s'], $_POST['time_m'], $_POST['time_h']);
    $this->distance = $_POST['distance'];
        $this->notes    = $_POST['notes'];
    //return $this->notes;
    $this->db->insert('runs', $this);
    }

Code:
An Error Was Encountered

Error Number: 1054

Unknown column '_parent_name' in 'field list'

INSERT INTO runs (id, date, tod, user_id, duration, distance, path_id, shoe_id, _parent_name, _ci_scaffolding, _ci_scaff_table, notes) VALUES ('', '', '', '', 2400, '5', '', '', 'Run_model', 0, 0, 'I ran today.')

Eh?


  active record bug on update
Posted by: El Forum - 10-10-2007, 11:01 AM - No Replies

[eluser]anurat[/eluser]
Hi All,
I found that if I put null value in where clause,
It will update the whole table. This is very serious
It should return an error and not execute the command
which is what happens if you use sql update statement.

Here is an example.

Code:
$id = null;
  $_data = array( 'csu_id' => 20 );
  $this->db->where( 'sl_id', $id );
  $this->db->update( 'storefront_lead', $_data );
All rows will have csu_id = 20

Thanks,
Anurat,


  Message: Undefined variable: data when trying to send HTML mail
Posted by: El Forum - 10-10-2007, 09:08 AM - No Replies

[eluser]spheroid[/eluser]
I'm able to send email by defining my HTML mail message within the code directly. But according to another post on the forums, I realized I could load a view. When I do I get this message:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: data

Filename: controllers/user.php

I'm loading my email config variables from email.php. Here is the code to load the view/create the email (partial):

Code:
$this->email->subject('Email Test. Is this your email address: '.$sendto);
$message = $this->load->view('email_welcome_test', $data, TRUE);
$this->email->message($message);
$this->email->send();

What can I do to fix this? Thanks in advance!!


  REST, API - confusion
Posted by: El Forum - 10-10-2007, 08:32 AM - No Replies

[eluser]tinawina[/eluser]
Before I get too far into my project..., I have a couple of questions about the best way to go about architecting our site. I've written about my project in this forum before. In a nutshell, we are putting together a site that archives research works (reports, data sets, etc.) and let's people login and post comments about works, tag them, save them to their own personal research library, etc.

In the end we want to make sure that our resources are easy to access and share not only through our site, RSS feeds and e-newsletters, but also through mashups that others might want to do.

I've been reading about REST and I find it confusing. Some people say use nouns to describe resources and move people through your site:

www.oursite.org/research/listing/the-name-of-a-report

Others say verbs are required:

www.oursite.org/research/getListing/the-name-of-a-report

I must confess, I have no idea why one way would be better than the other. Throw in API and mashup and I get really lost. Does anyone have a way to think about this or a process to use to figure out the best way forward? Especially given that I'm def using CI/OOP/MVC? Thanks for any insight!


  Help with custom query
Posted by: El Forum - 10-10-2007, 07:34 AM - No Replies

[eluser]FrankieShakes[/eluser]
Hey all..

I'm having a damn difficult time trying to figure out how to write a custom query to pull information from 2 DB tables.

The breakdown is this:

I have 2 tables: contact and contact_tel_numbers.

A contact can have many telephone numbers, and a number has an optional "primary" flag. So a contact MAY/MAY NOT have a primary number specified.

What I would like to do is display a list of contacts, and for those that HAVE a primary, display that. For those who don't have a primary, I'd like to display ANY of the numbers associated with their ID.

Having done strictly client-side (JS, Ajax, etc.) development for the last 18 months, trying to wrap my brain around this query hasn't been easy.

I'd appreciate any help anyone can offer.


Thanks!
-f


  Confirm dialog helper
Posted by: El Forum - 10-10-2007, 02:38 AM - No Replies

[eluser]Unknown[/eluser]
This create confirm dialog link ( you want confirm delete or something). Use it like ci orginal anchor(), but add few extra params. Needs jQuery and jQuery plugin: Impromptu

Add this inside your head tags:

Code:
function vhconfirm(v,m)
        {
            if( v )
            {
                var f =  document.createElement("form");document.body.appendChild(f);f.method = "POST";f.action = $("#" + v ).attr( "href" );f.submit();
            } else
            {
                return false;
            }
        }

And this one your helper dir.

confirm_helper.php
Code:
&lt;?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

    /**
    * confirm dialog helper
    *
    * autoload helpers confirm, url
    * example;
    * $attr = array( 'class' => 'delete' ) // just like Ci anchor();
    * $id = unique id to anchor
    * call this "confirm( 'item/delete' , 'Title' , $id ,$attr , array( ' dialog' => 'Confirm box text' ,' btrue' => 'true button text', bfalse => 'false button text'  ) );"
    *
    * requiments:
    *     jQuery www.jquery.com
    *    plugin Impromptu   http://trentrichardson.com/Impromptu/
    *
    * @ access public
    * @ param string            //  url if confirm is true
    * @ param intger            // id
    * @ param string            // text to confirm box title
    * @ param arr[optional]         //  defaults array( ' dialog' => 'Confirm delete?' ,' btrue' => 'Ok', bfalse => Cancel'  )
    * @ return string            // return anchor
    **/
    function confirm( $uri , $title, $id , $attr , $attr2 = array() )
    {
        $dialog     = array_key_exists( 'dialog' ,$attr2 ) ?  $attr2['dialog'] : 'Confirm delete?';
        $but_true     = array_key_exists( 'btrue' ,$attr2 ) ?  $attr2['btrue'] : 'Ok';
        $but_false     = array_key_exists( 'bfalse', $attr2 ) ?  $attr2['bfalse'] : 'Cancel';
        $attr['id'] = $id;
        $attr['onclick'] = "[removed] $.prompt( '".$dialog."' ,{ callback: vhconfirm , buttons: { ".$but_true.": '".$attr['id']."' , ".$but_false.": false } }); return false;";
        return anchor( $uri , $title , $attr );
    }
?&gt;

And then use it like:
Code:
&lt;?=confirm( 'blog/delete/'.$row->group_id , 'Delete' , 'conf'.$row->blog_id , array( 'class' => 'delete' ) , array( 'dialog' => 'Delete blog entry'.$row->entry_name.'?' ) )?&gt;


  Email library and Mass Sending
Posted by: El Forum - 10-09-2007, 11:24 PM - No Replies

[eluser]CodyPChristian[/eluser]
Note this is just a idea not actually coded or used yet.
I have a site where it has a user base and I need to send a HTML Newsletter out to them. Their emails are in a DB and since the email library can use a array as the TO input I figured it would be simple to send out the email. However a few issues come into play.

First any user I send this to can see all of the emails in the TO field, not good since these emails need to stay private.
Second I need to not be considered as spam because of this mass sending.
Third how would I do this with CI's class and not kill mysql at the same time for the mass sending.

Any knowledge and help with this is much appreciated.

Also I've never messed with making a HTML newsletter, from what I can find its rather simple to do.

Thanks again.


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

Username
  

Password
  





Latest Threads
hot-reload side effects s...
by PaulC
11 hours ago
CodeIgniter.com - Report ...
by Harry Lyre
11 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,991
» Latest member: busywood
» Forum threads: 78,389
» Forum posts: 379,450

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB