DooPHP IRC channel


DooView new features

Discussion about new desired features.

Re: DooView new features

Postby roman » Tue Jan 05, 2010 5:34 am

Francisco, why are you so keen on extending DooView? If you like Smarty so much, can you not keep using it in DooPHP based apps? I enjoy using PHPTAL, and that's what I use with this framework. I have no intention to start using DooView. Thank God, the framework doesn't require any template technology and makes it easy to use whatever one wishes to use.
roman
 
Posts: 442
Joined: Sat Aug 01, 2009 8:31 pm

Re: DooView new features

Postby magic22cn » Tue Jan 05, 2010 4:11 pm

roman wrote:Francisco, why are you so keen on extending DooView? If you like Smarty so much, can you not keep using it in DooPHP based apps? I enjoy using PHPTAL, and that's what I use with this framework. I have no intention to start using DooView. Thank God, the framework doesn't require any template technology and makes it easy to use whatever one wishes to use.


I don't think it's a better attitude when you wanna use something not compatible now with DooPHP.

Every time the user ask for some new features should be considered as a chance to enhance the framework but not to make trouble.

Extend DooPHP to compatible with Smarty, why not?It's a good suggestion b/c Smarty has a good market share and well developer base.

You can make it more sense when you try to persuade someone else migrate to DooPHP from other framework with Smarty just only b/c DooPHP also compatible with it.It's a lot of migration working time reduce.That's all.

BTW: I also have my request here!

I wanna extend DooView to compatible with CodeIgniter's view.

The reason why is quite simple because I have a project base on CI and I have a lot of views file I don't wanna touch them any more(I think a lot of other CI projects holder think so).

The major difference of php style view page between DooPHP and CodeIgniter is about variable.

DooPHP display vars like this:

Code: Select all
echo $data['xx']


But CodeIgniter do it like this:

Code: Select all
echo $xx


And what we only should done to make DooPHP to do the things same as CI is just add an line into renderc() function in DooView.php:

Code: Select all
extract($data);
//$this->data = $data;


This little change would make my life easier.Of course it make the performance a little lower than before but I can bear it ;)

But as you see, this kind of way to extend a framework, like DooPHP, is NOT quite grace.IMHO, I should extend the framework by make some new file and just edit some configuration and then done.But now I should read a lot of code to understand the way DooPHP works and edit the core code of it.I only wanna write the code under app/protected folder but do not touch anything under dooframework foloder.

Is it possible?

Thanks for any response!
magic22cn
 
Posts: 8
Joined: Mon Oct 19, 2009 4:23 am

Re: DooView new features

Postby RichardM » Tue Jan 05, 2010 5:00 pm

The use of $data[...] provides a nice way to sandbox a template. The designer only has access to the variables parsed into the $data array and therefore provides a safe(r) way to manage data. And personally I quite like DooPHP using this arrangement.

Also I dont see why you need to change your view files. Assuming they used the same tags as DooPHP ({{ and }}) for variable output then you have access to the data anyway as {{abc}} is changed to $data['abc'] and going for the extract and $abc would be the same.

If your using view files with php already embedded then you could look at running a regex find and replace over all the view files to convert from <?php echo $abc ?> to <?php echo $data['abc'] ?>

However if you do want to do your own thing in your protected folder you could look at writing your own class to extend DooView and then modify the nessecary parts to work as you want. You would then use this DooView in the same way you would configure another template engine. Some examples of this has already been documented on the forums for smarty and possibly phptal so I would releat it here.
Note: code samples my not be 100% accurate.
RichardM
 
Posts: 1329
Joined: Sun Aug 30, 2009 6:03 pm
Location: Cumbria, UK

Re: DooView new features

Postby roman » Wed Jan 06, 2010 12:14 am

magic22cn wrote:Extend DooPHP to compatible with Smarty, why not?

Is DooPHP incompatible with Smarty?
roman
 
Posts: 442
Joined: Sat Aug 01, 2009 8:31 pm

Re: DooView new features

Postby RichardM » Wed Jan 06, 2010 1:04 am

Smarty works with DooPHP.
Note: code samples my not be 100% accurate.
RichardM
 
Posts: 1329
Joined: Sun Aug 30, 2009 6:03 pm
Location: Cumbria, UK

Re: DooView new features

Postby magic22cn » Wed Jan 06, 2010 2:22 am

I know I know......But my concern is not which way is better, $xx or $data['xx'], but which way is more simple while I am MIGRATING!

I totally agree you said '$data[xx']' is more safer but how could if I have thousands of php style views file of CI should be change?The solution you said "regex find" can not be worked b/c CI do a stupid work here and you can not find with vars come from $data[''] and which one is from the others side.

But the fact is if I wanna migrate from CI to Doo, should I must change those view file?Can we find a more simple way to migrate my project first?runing it first?and make it more perfect and more like doo second?

You mention that I can extend dooview and change the code in Control to use my view class:

Code: Select all
public function view(){
        if($this->_view==NULL){
            Doo::loadCore('view/DooView');
            $this->_view = new DooView;
        }

        return $this->_view;
    }


Yes, I am quite sure It gonna be work just as my way: change just one line code in DooView class.

But you can see, I still touch the code of the core of the framework.

Can we do something like extending the control?such as pre control function or post control function?Could we can only wirte/change the codes in app/protected folder but not touch dooframework folder so that when I upgrade doo I can only copy&paste?

All the things I wanna to do is make my project be online as soon as possible after migrate from CI to Doo. I just wanna make it more graceful.The DooPHP is good so I wanna use it and kick away CI but I should balance the workload.

And this is just a suggestion but no kind of challenge.It seems here has a strong smell of gunpowder.

Smarty is just an example, forget it. :mrgreen:
magic22cn
 
Posts: 8
Joined: Mon Oct 19, 2009 4:23 am

Re: DooView new features

Postby RichardM » Wed Jan 06, 2010 2:34 am

I think that changing the DooPHP core code to fix your migration issue means then having to make changes for EVERYONE who asks and as such the code would become messy. I am still unsure where the issue is. If you where using templates then I would suspect that more of the tags in your views are going to be wrong for things like loops, condition statements etc???

If you really want to do your thing then extend your base controller (I assume you have one) so it has something like

baseController.php
Code: Select all
class BaseMyController extends DooController {

public function view() {
    if ($this->_view==null) {
        Doo::loadClass('MyDooView');
        $this->_view = new MyDooView();
    }
    return $this->_view;
}


then create a new php file in the class folder (of protected)
MyDooView.php
Code: Select all
Doo::loadCore('DooView');
class MyDooView extends DooView {
    public function renderc($file, $data=NULL, $controller=NULL, $includeTagClass=TRUE){
        extract($data);
        $this->controller = $controller;
        if($includeTagClass===TRUE)
            $this->loadTagClass();
        include Doo::conf()->SITE_PATH . Doo::conf()->PROTECTED_FOLDER . "/viewc/$file.php";
    }
}


Then when you change your views over you can simply remove the fix from your baseController.

Richard
Note: code samples my not be 100% accurate.
RichardM
 
Posts: 1329
Joined: Sun Aug 30, 2009 6:03 pm
Location: Cumbria, UK

Re: DooView new features

Postby leng » Wed Jan 06, 2010 2:42 am

@magic22cn I see you meant to modify renderc() to use extract() so you won't have to change anything for your CI view files. You can extend DooView (and DooController if required), not necessary have to modify the core dooframework.

protected/class/MyView.php
Code: Select all
Doo::loadCore('view/DooView');

class MyView extends DooView {
    public function renderc($file, $data=NULL, $controller=NULL, $includeTagClass=TRUE){
        //$this->data = $data;
        extract($data);
        $this->controller = $controller;
        if($includeTagClass===TRUE)
            $this->loadTagClass();
        include Doo::conf()->SITE_PATH . Doo::conf()->PROTECTED_FOLDER . "/viewc/$file.php";
    }
}


The reason I can't write this extract($data); to the core framework is very simple, DooPHP is not CI.
Just Doo IT!
leng
 
Posts: 1482
Joined: Thu Jul 16, 2009 11:33 pm

Re: DooView new features

Postby leng » Wed Jan 06, 2010 2:43 am

oh.. seems that Richard has posted the answer :oops:
Just Doo IT!
leng
 
Posts: 1482
Joined: Thu Jul 16, 2009 11:33 pm

Re: DooView new features

Postby RichardM » Wed Jan 06, 2010 2:59 am

leng wrote:oh.. seems that Richard has posted the answer :oops:


At least your response seems the same as mine...so hopefully the solutions works.


leng wrote:DooPHP is not CI.

:)
Note: code samples my not be 100% accurate.
RichardM
 
Posts: 1329
Joined: Sun Aug 30, 2009 6:03 pm
Location: Cumbria, UK

PreviousNext

Return to Features Request

Who is online

Users browsing this forum: No registered users and 0 guests

cron