 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
04-10-2009, 05:16 PM
|
#41 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
I uploaded a new version to the site with a few bug fixes and a new feature, templates!
Templates
They work just like views but are organized in a way that make them better for use in content management systems.
PHP Code:
// Choose Template Set $this->dingo->set_template('myset');
// Load Template $this->load->template('mytemplate');
|
|
|
|
04-10-2009, 11:11 PM
|
#42 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Could you perhaps explain what's so great about templates?
__________________
|
|
|
|
04-11-2009, 10:12 AM
|
#44 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by ETbyrne
|
I still don't understand what's so great about them.
It's a "group" of templates you say, but you can group views aswell?
Like having all views for the docs for example, in a docs subfolder in views folder. Then just $this->load->view('docs/viewfile');
I'm still wondering what the purpose of templates is, seeing as views in fact are templates aswell.
Quote:
|
Templates in Dingo work exactly like views, but they are organized in a way that makes them more ideal for use in content management systems than views.
|
How are they better "organized"?
__________________
|
|
|
|
04-11-2009, 01:10 PM
|
#45 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
I've not been following the changes in the framework very closely, mostly because there's no versioning repository yet (is there?). However:
Quote:
|
Templates in Dingo work exactly like views, but they are organized in a way that makes them more ideal for use in content management systems than views.
|
Ideal for use in CMS? What about all of the other uses of such a framework; why just CMS? Also, as I said I've not looked at the code but why use templates, or templates and views, or just views?
|
|
|
|
04-11-2009, 03:04 PM
|
#46 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Quote:
I still don't understand what's so great about them.
It's a "group" of templates you say, but you can group views aswell?
Like having all views for the docs for example, in a docs subfolder in views folder. Then just $this->load->view('docs/viewfile');
I'm still wondering what the purpose of templates is, seeing as views in fact are templates aswell.
|
Yes, you can group views, but let's say you have a CMS that lets the admin change the site 'template'. In order to change the 'template' you are using then you would have to go through all the source code and change $this->load->view('group1/viewfile'); to $this->load->view('group2/viewfile');
But with templates doing that across the entire site would be as easy as this in an auto-loaded helper:
PHP Code:
$this->dingo->set_template('group2');
Plus templates have the advantage of that if you are looking for a template in a group (set) other than the default one and it isn't found, it will then try to load that template from the default set. Something that is regularly done by content management systems.
Quote:
|
Ideal for use in CMS? What about all of the other uses of such a framework; why just CMS? Also, as I said I've not looked at the code but why use templates, or templates and views, or just views?
|
They can be used instead of views for any website if you want, it's the fact that you can switch between multiple template sets that make templates ideal for content management systems where the administrator usually isn't going to edit the source code.
Perhaps I should just get rid of views entirely... Thanks for the feedback everyone!
|
|
|
|
04-11-2009, 05:35 PM
|
#47 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
What is the difference between templates and views (in your personal oppinion)?
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|
04-11-2009, 10:51 PM
|
#48 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Quote:
|
What is the difference between templates and views (in your personal oppinion)?
|
Templates are views organized in a better, more modular way.
Btw I want to change the syntax used to change the current template set, $this->dingo->set_template() just aint workin for me.
|
|
|
|
04-11-2009, 11:42 PM
|
#49 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Here are some ideas for the new syntax for using templates, please tell me which one(s) you like most.
Current One:
PHP Code:
// Set Template Group $this->dingo->set_template();
// Use Template $this->load->template();
Possibilities
1
PHP Code:
// Set Template Group $this->template->group();
// Use Template $this->template->load();
2
PHP Code:
// Set Template Group $this->template->group();
// Use Template $this->load->template();
3
PHP Code:
// Set Template Group $this->template->group();
// Use Template $this->template->use();
|
|
|
|
04-11-2009, 11:43 PM
|
#50 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
I just read abit more on the code, system/classes/files.php:
- No failure check if fopen fails in the constructor?
- No option to skip the locking call?
- Why not use streams here, the Streams API have alot more functions built in (I know internally fopen uses streams)
- Theres no check for if an file handle is valid or not:
PHP Code:
$f = new file;
$f->close();
$f->write('bogus');
In the DingoLoad::view() method, the extract() call should be after the foreach, else it may overwrite $this (I know its not very likely), plus it might also overwrite $view.
In the DingoInput class, you should use isset, instead of @. You may also find this article by Derick interesting:
http://derickrethans.nl/five_reasons...be_avoided.php
Other lookings at the framework, I feel that the following topics lacks abit: - Error handling, you should use an error/exception handler and make it possible to show non fatal errors in a view for example, or automaticlly creation of an error view if for example a controller threw "throw new RuntimeException('blah blah blah');" (RuntimeException in this case from SPL)
- Database access layer, the current is not even a layer so its hard to deal with multiple database types within the same API
Thats it for now ;)
__________________
|
|
|
04-11-2009, 11:54 PM
|
#51 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Kalle, I'll see what I can do about the file class and replace the @s with isset() in Dingo::input and the other classes. I realize the database needs (a lot of) work, and I'm working on it at my own snails pace right now...
Do you know of any good articles/tutorials on PHP error handling I can look at?
Thanks!
|
|
|
|
04-12-2009, 12:12 AM
|
#52 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Oh, I see the point then.
But the template "files", how would they be coded ? Like regular view files?
__________________
|
|
|
|
04-12-2009, 12:22 AM
|
#53 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
For error handling I used a simple way;
- I have a function to store global shared variables, my implementation of such a function is similar to how an extension global is in C in the php source:
PHP Code:
function PG($name, $value = NULL)
{
static $variables;
if(!$variables)
{
$variables = Array();
}
if(func_num_args() > 1)
{
$variables[$name] = $value;
}
elseif(!array_key_exists($name, $variables))
{
return(false);
}
return($variables[$name]);
}
Then I allocate a default element to carry the non fatal errors, notice that this is an ArrayObject and now just a regular Array(). This is due to PHP doesn't support function dereferencing.
PHP Code:
PG('errors', new ArrayObject);
- In the boostraper I also define a custom error and exception handler, set by set_[error|exception]_handler. The exception handler will check if an exception is fatal or not (depending on which one you send):
PHP Code:
function dingo_exception_handler(Exception $e)
{
/* Simply consider any exception not of the default exception class fatal */
if(get_class($e) == 'Exception')
{
PG('errors')->append($e->getMessage());
return;
}
/* Format the error message, if you are in debug mode you can expose the path and line number (requires 'PG('debug')' defined */
$format = '%s';
if(PG('debug'))
{
$format = '%s in %s on line %d';
}
$message = sprintf('%s' . (PG('debug') ? ' in %s on line %d' : '')), $e->getMessage(), $e->getFile(), $e->getLine());
/* $dingo->set_template_and_vars(), $dingo->view() */
}
And the same with the error handler:
PHP Code:
function dingo_error_handler($severity, $message, $file = NULL, $line = NULL)
{
/* Respect the current error_reporting setting */
if(!(error_reporting() & $severity))
{
return;
}
$fatal = false;
switch($severity)
{
case(E_RECOVERABLE_ERROR):
{
$prefix = 'Recoverable error';
$fatal = true;
}
break;
case(E_USER_ERROR):
{
$prefix = 'Fatal error';
$fatal = true;
}
break;
case(E_NOTICE):
case(E_USER_NOTICE):
{
$prefix = 'Notice';
}
break;
/* E_DEPRECATED & E_USER_DEPRECATED, available as of PHP 5.3 - Use their numbers here to prevent redefining them and two E_NOTICE's */
case(8192):
case(16384):
{
$prefix = 'Deprecated';
}
case(E_STRICT):
{
$prefix = 'Strict standards';
}
break;
default:
{
$prefix = 'Warning';
}
}
$error = sprintf('%s: %s' . (PG('debug') ? ' in %s on line %s' : ''), $prefix, $message, ($file ? $file : 'unknown'), ($line ? $line : 'unknown'));
if($fatal)
{
/* Handle a fatal error here, like exceptions */
}
elseif(PG('debug'))
{
/* Only add these non fatal errors to the error stack if we're in debug mode to prevent the user from seeing these */
PG('errors')->append($error);
}
}
- When compiling the errors into an error message you can do like (basic HTML):
PHP Code:
$html = 'No errors!';
if(($errors = PG('errors')) && sizeof($errors))
{
$html = '<h1>Errors</h1>' .
'<ul>';
foreach($errors as $error)
{
$html .= '<li>' . $error . '</li>';
}
$html .= '</ul>';
}
echo($html);
Hope this is easy enough to understand with the comments (as its 2:22 here, I better get some sleep)
ps. as a quick remark about option #3 in your previous post; you cannot use the name "use", its a reserved keyword as of PHP 5.3 ;)
__________________
Last edited by Kalle : 04-12-2009 at 01:56 AM.
|
|
|
04-12-2009, 12:54 AM
|
#54 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Quote:
Oh, I see the point then.
But the template "files", how would they be coded ? Like regular view files?
|
View, Helper, and Template files are all coded the same. It's just easier for the developer that way.
Kalle, wow! That was very helpful, I'm eternally thankful!
|
|
|
|
04-12-2009, 09:09 AM
|
#55 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
Quote:
Originally Posted by ETbyrne
Templates are views organized in a better, more modular way.
Btw I want to change the syntax used to change the current template set, $this->dingo->set_template() just aint workin for me.
|
Really? How's that? What is it that makes a template modular? It's a piece of code that adds to the building of the visible part of an application (website or not). So...what is it so modular about that? It's the implementation of the views/templates system that makes a difference, not the template/view files themselves.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|
04-12-2009, 04:05 PM
|
#56 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
I don't know about you xenon, but I was talking about in terms of Dingo... Not just in general. Yeah you are right it's the implementation system that makes them different, but I don't really see that as a problem.
Last edited by ETbyrne : 04-13-2009 at 12:08 AM.
|
|
|
|
04-17-2009, 10:45 PM
|
#57 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
I uploaded a new version of dingo to the site and as always it has many changes. To name a few:
Error Handling - Thanks to Kalle Dingo now handles errors with grace and also has a debugging mode (set in index.php)
More URL Access - Pages can now be accessed via index.php?page=controller/func/arg1/arg2 in addition to index.php/controller/func/arg1/arg2. This fixes an issue with resolving paths when using Mod_Rewrite.
Dingo also comes with a nice little styled welcome page, I thought it would be better than the usual blank white "installation successful" thing.
And just some all around bug fixes across the board. The site is also now accessible to everyone now, but it isn't "officially public" so don't go spreading the word quite yet!
Quote:
|
I've not been following the changes in the framework very closely, mostly because there's no versioning repository yet (is there?)
|
Yeah, I haven't set up a code repository yet...
|
|
|
|
04-17-2009, 11:23 PM
|
#58 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
I looked at the templates or views, or what you called thme in /application/errors/, most of them are exactly the same, wouldn't it be more logical to just have a $error_type that differs from "Warning", "Fatal", etc. Also remember that fatal errors (E_USER_ERROR and E_RECOVERABLE_ERROR being the only one that can be caught) should terminate execution because something *critical* happened.
Another thing I came across, why implement a File object when SPL already does that in a nice and easy manner:
http://www.php.net/splfileinfo
;)
__________________
|
|
|
04-18-2009, 12:08 AM
|
#59 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
I split the errors into different files because I thought people may want to style fatal errors differently from warnings... I'm not entirely sure if that is necessary though...
I'll take a look into the files thing
|
|
|
|
04-18-2009, 06:58 PM
|
#60 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
OK, I reduced the number of error files down to "Fatal" and "Non-Fatal". New Dingo uploaded.
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|