nova-framework / framework

Demo application using Nova - this is an extensive playground, use "app" repository for real applications.
http://novaframework.com/
MIT License
418 stars 210 forks source link

SMVC restructure #222

Closed dcblogdev closed 8 years ago

dcblogdev commented 8 years ago

I've given the framework a bit of a restructure so it main files are outside of the web root by default and the only files that should be inside the web root are the templates, .htaccess and index.php.

so the structure is now like this:

app
    Controllers
    Core
    Helpers
    Language    
    logs
        error.log
    Models
    Modules
    vendor
    views
    composer.json
public_html
    templates
        default
    .gitignore
    .htaccess
    index.php
    licence.txt

From the index.php the starting path would be:

$smvc = '../';

The vendor path would be

if (file_exists(SMVC.'app/vendor/autoload.php')) {
    require SMVC.'app/vendor/autoload.php';
}

I've also adjusted the view class and url helper to make the paths more flexible.

This would mean all public files (templates) would be in the web root all classes would be outside the web root.

The logger class has been changes since it would no longer be able to serve html errors they would be stored in app/logs/error.log above the document root.

This kind of setup needs to happen, it's a basic security practice. I'm very late in changing this.

First off is there any objections to this?

Additionally should this be a sub part update 2.2.1 or warrant a full version increase? personally I think 2.2.1 would be sufficient no new functionality has been added.

Another area I'm not 100% on is Modules. They may need to be in the web root as well so any modules containing css can be loaded but at the same time they will contain classes so should be above the root! will require some thought on this one.

I haven't pushed this up yet I'm waiting to get your thoughts on this.

jimgwhit commented 8 years ago

Get some rest! That's an order, hehe. Where is @volter9 during all this?

jimgwhit commented 8 years ago

No one else has any testing results?

woodsy1 commented 8 years ago

I will want to do some testing to work out how got FTP will cope with this change. Especially a change in folder structure when changing between development and production.

I am assuming that you can run the production setup in local xamp servers? ( have the folders above htdocs?)

woodsy1 commented 8 years ago

*git ftp

dcblogdev commented 8 years ago

yes the paths are updated to point above htdocs.

woodsy1 commented 8 years ago

I'll try give it a whirl tonight with git FTP then to see how that will work. Dave if you like I can teach you how to use that so you have a better process for pushing to production!

jimgwhit commented 8 years ago

@daveismyname and @woodsy1 I have tested on local dev both ways, having all under htdocs, it's htdocs on my machine not public_html, and having app, system, and vendor a level higher than htdocs. Both setups work. I also tested on godaddy shared hosting, so far it works. But you should be able to develop the usual way and just do a separation when you upload to production. But a separation isn't required, it still works either way. Doesn't git put the files where you tell them? And where is a tutorial on that Git ftp you are talking about? I want to learn that to.

dcblogdev commented 8 years ago

I've recorded a video covering moving folders above the document root https://www.youtube.com/watch?v=hQiZtVd34d0

Thanks for the offer yes I'd like that.

jimgwhit commented 8 years ago

The last video was good, oh boy another video. I got it solved, but am going to watch the video anyway.

nekomajin commented 8 years ago

Local it works for me. On the server I'm going to test it. Very good @daveismyname! :thumbsup:

jimgwhit commented 8 years ago

@daveismyname video 2 was good. Until now, I didn't know that was possible on godaddy, but there are host where all has to be under the public_html. So thanks for ensuring flexibility.
What php editor are you using in the videos? And will it work on windows 10?

woodsy1 commented 8 years ago

@Jimgwhit thanks for that summary. My concern here is that with a potential change in folder name from htdocs locally to public_html on the server git FTP might have issues. I'll test and see On Dec 6, 2015 8:10 AM, "jimgwhit" notifications@github.com wrote:

@daveismyname https://github.com/daveismyname video 2 was good. Until now, I didn't know that was possible on godaddy, but there are host where all has to be under the public_html. So thanks for ensuring flexibility.

— Reply to this email directly or view it on GitHub https://github.com/simple-mvc-framework/framework/issues/222#issuecomment-162247514 .

woodsy1 commented 8 years ago

He uses sublime text editor. I presume brackets.io

woodsy1 commented 8 years ago

Prefer*

dcblogdev commented 8 years ago

@woodsy1 does everything I need and goes it quickly, what's better about brackets? I really like the integrated FTP, project switcher plus I've got snippets written for sublime text so helps speed writing code.

volter9 commented 8 years ago

@jimgwhit I'm really busy now, I don't have much time. I think that everything in the system folder should go to the separate repo smvc/core and be required in composer.json for project template. I never really liked everything in the app directory.

My suggestion would be to separate core of framework to separate repository and publish it as separate package. There would be another smvcf package called smvcf/project which would be project template which would consist out of two folders: app/ and public. There's also would be files like composer.json with required SMVCF core package. That's where unit testing comes handy.

That's my opinion and I'm not forcing it, therefore I'm not really into discussing it's pros and cons.

jimgwhit commented 8 years ago

@woodsy1 what's the difference, before it was still htdocs wasn't it? I develop on a bitnami stack and it's htdocs. But on godaddy it's public_html. That hasn't changed.

woodsy1 commented 8 years ago

The difference is that now we will have to store our root folder in the repo so if we push to server (using git FTP push ) then the folder names are difference and it would push a htdocs up instead of a public_html.

I'll do testing with it tonight. On Dec 6, 2015 9:07 AM, "jimgwhit" notifications@github.com wrote:

@woodsy1 https://github.com/woodsy1 what's the difference, before it was still htdocs wasn't it? I develop on a bitnami stack and it's htdocs. But on godaddy it's public_html. That thas't changed.

— Reply to this email directly or view it on GitHub https://github.com/simple-mvc-framework/framework/issues/222#issuecomment-162252383 .

woodsy1 commented 8 years ago

The solution may well be to change the webroot of my local server to reference a public_html. On Dec 6, 2015 9:41 AM, "daniel wood" daniel.wood.00@gmail.com wrote:

The difference is that now we will have to store our root folder in the repo so if we push to server (using git FTP push ) then the folder names are difference and it would push a htdocs up instead of a public_html.

I'll do testing with it tonight. On Dec 6, 2015 9:07 AM, "jimgwhit" notifications@github.com wrote:

@woodsy1 https://github.com/woodsy1 what's the difference, before it was still htdocs wasn't it? I develop on a bitnami stack and it's htdocs. But on godaddy it's public_html. That thas't changed.

— Reply to this email directly or view it on GitHub https://github.com/simple-mvc-framework/framework/issues/222#issuecomment-162252383 .

jimgwhit commented 8 years ago

@woodsy1 that doesn't make any since, if you are developing under a htdocs folder now, and host has public_html well how are you doing it now? Not to be rude here, but you are trying to over complicate it. So you are telling me you can't even push now because of name conflicts? There has to be a way, have you dug into the git docs? People do this all the time, just look at the laravel forum, there people are developing under a htdocs folder, but manage to push or whatever to a live server / host. There has to be an automated task for such a push.

jimgwhit commented 8 years ago

@woodsy1 are you saying that you want the framework only to be available to people who's development server happens to have public_html as the folder that sites go beneath, and no one can develop if they fall under www, or htdocs?

woodsy1 commented 8 years ago

@daveismyname we should take the comparisons of editors off this thread so to keep it on topic. I will create a thread on the forums with my thoughts to get the ball started :)

@jimgwhit When you have to preface your statement with "not to be rude here" it means your being rude ;) I am not overcomplicating things. I am trying to simplify things! When using git ftp I can type 1 command into my command prompt and push all my latest commits to my server without manually having to remember where they go or what I have changed.

The reason it becomes complex is because we no longer have a folder that everything sits under that we can put directly into the git repos. At the moment I have the entire folder sitting in a repo and it is easy but with the proposed design things will be above the web root which will mean that we will have to include the webroot folder in the repo as well. As I have said I havent tested anything yet so I am not sure how this will work (I will have time tonight to test). There are 2 concerns I have that might be an issue for the automatic git ftp approach.

  1. If the webroot folder on local dev is called something different to the server then it would put the files in a different location on the server.
  2. If you have multiple sites in your local dev server. (I think its possible to exclude items from the repo when you select a folder but I will have to test it)

Again I havent tested anything yet I was just flagging this could be a potential issue for what is currently the best way of deploying to servers when developing with PHP. (Plain of ftp is far to prone to user error for me!)

woodsy1 commented 8 years ago

@jimgwhit and of course not we are a community and trying to develop a framework that is suitable to all!

jimgwhit commented 8 years ago

@woodsy1 OK, sorry if I mis-understood, but I am just totally confused on what you are talking about. Yii, Laravel, and some other frameworks have done the out of public_html for a while now. How are these folks deploying? Since we know there is a way I don't see where there is even an issue on this, that has anything to do with SMVC. Ask yourself this if you were using laravel, how would you achieve that task?

woodsy1 commented 8 years ago

I don't use any of those frameworks so I don't know! I don't know how it would be achieved and that's why I have raise the issue! On Dec 6, 2015 2:47 PM, "jimgwhit" notifications@github.com wrote:

@woodsy1 https://github.com/woodsy1 OK, sorry if I mis-understood, but I am just totally confused on what you are talking about. Yii, Laravel, and some other frameworks have done the out of public_html for a while now. How are these folks deploying? Since we know there is a way I don't see where there is even an issue on this, that has anything to do with SMVC. Ask yourself this if were using laravel, how would you achieve that task?

— Reply to this email directly or view it on GitHub https://github.com/simple-mvc-framework/framework/issues/222#issuecomment-162268619 .

jimgwhit commented 8 years ago

Well, then we'll figure it out.

yeshelolo commented 8 years ago

Dear Dave,

I went through the videos you made, thanks for this it explains well.

I like very much the KISS approach of the framework and in that spirit, I would like to continue to have everything in one single folder per app. I do not have any security issue here since my apps are not on internet. And this also make my life easier for eclipse PDT / Git / backups devs.

Even though, folders can be adjusted manually after framework download, it would be nice to deliver an installation package that is ready to go for the 'all-in-one-folder' option. Would you consider providing that package in 3.0 ?

If not I can live without, I will jus have to tailor folders manually after each download.

nhymxu commented 8 years ago

Again, don't put config file in system folder :joy:

dcblogdev commented 8 years ago

why?

nhymxu commented 8 years ago

system folder is read-only folder. config can dynamic change. you should put config file in app folder.

P/s: In app folder, create helpers folder for user-helper files. Like CodeIgniter structure.

I know you want build simple framework where developer can custom Core. But I don't think it's good all time.

dcblogdev commented 8 years ago

I disagree it really makes no sense to put config in the app folder none of the are really read only they can all be written to. With that logic quite a few other file should be in the app folder as they have dynamic elements to them. I really don't see what benefit it would have placing it in the app folder.

Even in CI it's in the system/Core folder.

dcblogdev commented 8 years ago

@yeshelolo

Even though, folders can be adjusted manually after framework download, it would be nice to deliver an installation package that is ready to go for the 'all-in-one-folder' option. Would you consider providing that package in 3.0 ?

I'm working on a CLI utility so far it can make controllers, views and models. I'm working on an installer section to be able to set the config and htaccess files from the CLI having the ability for it to configure the structure paths too would mean you would not have to manually update your structure.

It's very much a work in progress but that could work for your need.

jimgwhit commented 8 years ago

@yeshelolo you said:

Even though, folders can be adjusted manually after framework download, it would be nice to deliver an installation package that is ready to go for the 'all-in-one-folder' option. Would you consider providing that package in 3.0 ?

The thing is, you have folks who want it up a folder, and others who wnat it the way it was. @daveismyname has now made it so it works either way. In the video, it took Dave all of two minutes to move some files, and change 3 lines in index.php. I think what he's accomplished to please everyone is pretty darn good. Just my two cents.
Also, I tested both ways, it did not take very long. I only had a little problem with resolving paths, but once you do that once, there should be no problems.
In fact, the videos, and this issue # we are in right now completely covers what to do.

dcblogdev commented 8 years ago

Thanks @jimgwhit I appreciate that, it's incredibly difficult to please everyone.

jimgwhit commented 8 years ago

@daveismyname I tell you, everything is looking good, are you almost ready to commit it to ver 3.0?
I'm sure you want to test more. Oh, I don't use assets.php, I renamed it to assets.bak, I just call files the regular way like

<link href="<?php echo Helpers\Url::templatePath(); ?>default/css/style.css" rel="stylesheet">
<script type="text/javascript" src="<?php echo DIR; ?>public/js/jquery.js"></script>   

and it works good. I guess I am confused about assets.php, because until I renamed it I got an error. What is that file doing in the background?

dcblogdev commented 8 years ago

I think that's due to the caching I've come across that too need to nail it down more, for now I've set cache to false as default.

I'm going to test more before I release to 3.0, it would be great to have the CLI utility ready at the same time too.

it's completely optional but can save time on common tasks.

jimgwhit commented 8 years ago

Forgot to mention, I never got errors in ver 2.2 from that file. And what is a cli utility?

dcblogdev commented 8 years ago

it's a change for 3.0 so the cache was not in 2.2 so that will be why :)

it's a command line script for instance to create a controller with some methods you would type:

php smvc make:controller Contacts index add edit delete import export

would create a controller called Contacts with 6 methods.

dcblogdev commented 8 years ago

it's not in the beta yet in case you was wondering.

jimgwhit commented 8 years ago

@daveismyname even after more test and tweaks, will the final ver 3.0 be close to the beta ver? In other words the same install instructions as the two videos showed.
And is it fine to rename assets.php to .bak since I don't use it?

dcblogdev commented 8 years ago

Yes to both questions, since your not calling it at all it doesn't matter what it's called. At this point I don't see the need to change the structure again it now caters for flexible paths.

I still haven't got around to looking into testing I'll cross that bridge when I get to it. But I don't want to change the structure again unless there is a genuine need for it.

jimgwhit commented 8 years ago

The CLI would be good for some folks, but I can't believe folks can't just make a boilerplate controller, and do a simple copy paste and just rename it to new controller name. That's what I do, and I imagine you also.

dcblogdev commented 8 years ago

Yes I do that a lot, but manually creating it and the views is a lot slower then writing a line out on the CLI like I've said it will be completely optional, so you don't need to touch if you don't want to.

jimgwhit commented 8 years ago

I will say this, you have come a long way since the very firsrt version, which I didn't use, I started using SMVC when you implemented the new router.

dcblogdev commented 8 years ago

Indeed! it's been quite a journey learnt a lot on the way, still a lot to learn the beauty of programming! lol

jimgwhit commented 8 years ago

@daveismyname a side note, what's funny is I have used cakephp, and they have cake bake which generates all code. I didn't like that and still wrote all my own code. The baked code needed too much modification.

jimgwhit commented 8 years ago

I started out programming before Windows even existed in Dbase 3 in DOS.

dcblogdev commented 8 years ago

I'm sure for a lot of people that will still be the case but nice to have the option.

Never heard of it, but I do remember learning the doc commands years ago though I never did anything with it.

jimgwhit commented 8 years ago

My first computer, booted from a large floppy disk.

jimgwhit commented 8 years ago

Get more rest.