I've installed Zend Studio 7.1.1 that contains 1.9 framework.
For the server side, I use easyphp (very similar to wamp)
When I create the project, I obviously obtain this architecture:
MyProject
|-- application
| |-- Bootstrap.php
| |-- configs
| | `-- application.ini
| |-- controllers
| | |-- ErrorController.php
| | `-- IndexController.php
| |-- models
| `-- views
| |-- helpers
| `-- scripts
| |-- error
| | `-- error.phtml
| `-- index
| `-- index.phtml
|-- library
|-- public
| |-- .htaccess
| `-- index.php
`-- tests
|-- application
| `-- bootstrap.php
|-- library
| `-- bootstrap.php
`-- phpunit.xml
To launch the project, I enter:
http://127.0.0.1/MonProjet/public/index.php
But when I create a new controller (TestController.php) and the associated view (application.views/test/index.phtml) and when I enter:
http://127.0.0.1/MonProjet/public/test
the browser returns the error : object not found (404).
although I activated the mod_rewrite
LoadModule rewrite_module modules/mod_rewrite.so
So, how can I set the routing mechanism to reach the new controllers and their views?
Thank you very much,
regards.
It's been quite a while since the question was asked, but nevertheless maybe somebody is still facing the issue. I had the same problem today and it turned out that in apache configuration in httpd.conf the "AllowOverride" was set to "none" and therefore the .htaccess could not be read. Changing it to "All" solved the problem.
Your index.php file has the Autoloader class call which loads all the controller and models automatically.
Along with that you can also add this code in your BootStrap.php file.
protected function _initAutoload()
{
$modeLoader = new Zend_Application_Module_Autoloader(array
('namespace'=>'Application','basePath'=>APPLICATION_PATH ));
return $modeLoader;
}
Related
#Update:
Changing the task from shared_task to app.celeryd.celery.task solves the issue. Is there some additional setup for shared_tasks to work properly?
Completely rewritten still the same error. I'll try to keep it relatively short. The new project structure is a bit cleaner and looks as follows:
proj
|-- app
| |-- controller
| | |-- __init__.py
| | +-- greeting_model.py
| |-- model
| | |-- __init__.py
| | +-- dto
| | |-- __init__.py
| | +-- greeting_dto.py
| |-- service
| | |-- __init__.py
| | +-- greeting_service.py
| |-- tasks
| | |-- __init__.py
| | +-- greeting_tasks.py
| |-- __init__.py
| |-- celeryd.py
| +-- flaskd.py
|-- test.py
|-- worker.py
+-- ws.py
I'm initializing celery and flask separately and provide worker.py which shall be run on client machines, while ws.py (the flask web service) will run on another. Celery initialization is plain simple, and uses rpc backend with RabbitMQ broker. The 2 queues for now are static but later those will be populated from configuration.
from kombu import Queue
from celery import Celery
celery = Celery('LdapProvider',
broker='amqp://admin:passwd#localhost:5672/dev1',
backend='rpc',
include=['app.tasks.greeting_tasks'])
celery.conf.task_queues = (
Queue("q1", routing_key="c1.q1"),
Queue("q2", routing_key="c2.q2"),
)
Worker.py (used to launch celery worker - overly simplified for this question):
from app.celeryd import celery as celery
from celery.bin.worker import worker
if __name__ == '__main__':
celeryd = worker(app=celery)
options = {
'broker': 'amqp://admin:passwd#localhost:5672/dev1',
'queues': 'q1',
'loglevel': 'info',
'traceback': True
}
celeryd.run(**options)
I'll omit flask initialization and jump to greeting_service.py which calls the celery task:
# greeting_service.py:
from app.celeryd import celery
from app.tasks.greeting_tasks import say_hello
class GreetingService(object):
def say_hello(self, name: str) -> str:
async_result = say_hello.apply_async((name,), queue='q1')
return async_result.get()
# greeting_tasks.py
from celery import shared_task
#shared_task(bind=True)
def say_hello(self, name: str) -> str:
return name.capitalize()
This call fails through flask whatever I try. I created test.py just to test if celery works at all:
from app.celeryd import celery
from app.tasks.greeting_tasks import say_hello
if __name__ == '__main__':
async_result = say_hello.apply_async(('jackie',), queue='q1')
print(async_result.get())
Pretty much the same as greeting_service.py it's just not called from greeting_controller which is a flask_restplus namespace. The difference that test.py results in:
/home/pupsz/PycharmProjects/provider/venv37/bin/python /home/pupsz/PycharmProjects/provider/test.py
Jackie
Process finished with exit code 0
[2020-01-16 18:56:17,065: INFO/MainProcess] Received task: app.tasks.greeting_tasks.say_hello[bb45e271-563e-405b-8529-7335a3810976]
[2020-01-16 18:56:17,076: INFO/ForkPoolWorker-2] Task app.tasks.greeting_tasks.say_hello[bb45e271-563e-405b-8529-7335a3810976] succeeded in 0.010257695998006966s: 'Jackie'
while through flask all I get is the already shown and the worker log does not show any incoming task meaning through flask apply_async is not sending the task to RabbitMQ:
File "/home/xyz/PycharmProjects/proj/app/service/greeting_service.py", line 8, in say_hello
return async_result.get()
NotImplementedError: No result backend is configured.
Please see the documentation for more information.
I found one similar problem with django without an answer so I'm kind of stuck and would appreciate some kind of guidance.
Solution: The solution to have the shared_task work as expected was answered here: LINK
Modifying celerz initization as:
from kombu import Queue
from celery import Celery
celery = Celery('LdapProvider',
broker='amqp://admin:passwd#localhost:5672/dev1',
backend='rpc')
# include=['app.tasks.greeting_tasks'])
celery.conf.task_queues = (
Queue("q1", routing_key="c1.q1"),
Queue("q2", routing_key="c2.q2"),
)
celery.set_default()
Even if I were to remove the commented out include line the worker successfully picks up the shared_task defined in app.tasks.greeting_tasks:
[tasks]
. app.tasks.greeting_tasks.say_hello
After the app was set to default_app() no more NotImplementedError was thrown even when using shared_task. As for the reason... I have no idea, it was 6 hours of trial and error of different configs and googling. I find the official documentation lackluster in certain more complex situations.
I am trying to find a line of code to all my files with a specific file name criteria. I am trying to take advantage the Advanced Search of the Visual Studio Code by putting a wildcard in the files to include field of the search. But I wasn't able to achieve that. I tried to use asterisk (*) symbol, but I think the Visual Studio Code does not accept that. So I tried to search the internet and found this solution by using the .+?; however, it still does nothing.
Search Keyword: ICustomMatColumn
files to include: (wildcard)viewmodel.ts
Apparently, the Visual Studio Code supports glob syntax which is really great. To achieve the desired result in the question you just need to do this format
./**/*< partialFileName >
Example
Folder Structure:
|-- app
|-- users
|-- list.ts|html|css|viewmodel
|-- form.ts|html|css|viewmodel
|-- cars
|-- list.ts|html|css|viewmodel
|-- form.ts|html|css|viewmodel
|-- configurator.ts|html|css|viewmodel
|-- app.component.ts|html|css
|-- app.module.ts
|-- user.service.ts
|-- car.service.ts
|-- index.html
|-- main.ts
|-- style.css
Let's Assume that every ViewModel file has this word/code/string ICustomMatColumn
Search Keyword: ICustomMatColumn
Files to Include: ./**/*ViewModel.ts
Search Result:
|-- app
|-- users
|-- list.ts|viewmodel
|-- form.ts|viewmodel
|-- cars
|-- list.ts|viewmodel
|-- form.ts|viewmodel
|-- configurator.ts|viewmodel
It will strictly include only the files with the partialFileName that you entered in the files to include field
So I found that the asterisk (*) works when you put in the files to include field the higher level folder name as the criteria
The format will be higherLevelFolderName*
Example:
Folder Structure:
|-- app
|-- users
|-- list.ts|html|css|viewmodel
|-- form.ts|html|css|viewmodel
|-- cars
|-- list.ts|html|css|viewmodel
|-- form.ts|html|css|viewmodel
|-- configurator.ts|html|css|viewmodel
|-- app.component.ts|html|css
|-- app.module.ts
|-- user.service.ts
|-- car.service.ts
|-- index.html
|-- main.ts
|-- style.css
Let's Assume that every ViewModel file has this word/code/string ICustomMatColumn
Search Keyword: ICustomMatColumn
Files to Include: app*
Search Result:
|-- app
|-- users
|-- list.ts|viewmodel
|-- form.ts|viewmodel
|-- cars
|-- list.ts|viewmodel
|-- form.ts|viewmodel
|-- configurator.ts|viewmodel
But the CONS of this solution is in case your search criteria is present in the other file, it will be included to the search result.
I have been given a skeleton SBT project to work on. The directory structure is as follows:
|-- build.sbt
|-- project
| |-- build.properties
| |-- plugins.sbt
| |-- project
| `-- target
|-- README.md
`-- src
|-- main
| `-- scala
| `-- com
| `-- app-name
| |-- domain
| |-- exception
| |-- repository
| `-- util
`-- test
`-- scala
`-- Vagrantfile
The instructions are to create an app entry point which should take a single command line argument and run some logic.
I have managed to get a simple "hello world" sbt project working but I'm new to scala/sbt. Where would I place this entry point and how can I accept a command line argument?
The root folder for source files would be src/main/scala.
Parameters are referenced using the args array within your entry point object.
The entry point is any object under that source tree which extends App. Since this is a hello world example and you're just getting started, I'd drop it right into the root of the sources (src/main/scala/MyApp.scala).
Something like this:
object MyApp extends App {
println(args.length match {
case 0 => "You passed in no arguments!"
case 1 => s"You passed in 1 argument, which was ${args(0)}"
case x => s"You passed in $x arguments! They are: ${args.mkString(",")}"
})
}
To run your app, issue the sbt run command in the project root. To run with parameters, do sbt run "arg1".
I am trying to figure out how autoloading function with Zend Framework.
questions:
1 - say I want to add to my application/ folder a folder called x/ containing a class named Foo.php. How do I get it auto-loaded when I do new Foo() from a controller? And then how should I name The class Foo? Is "Foo" alright or should I use the name "Application_X_Foo"?
2 - whats this story with $autoloader->registerNamespace('My_')? I mean where should the classes in the namespace My_ live?
Thanks
1.- For application specific classes you should use Application_Model_Foo as the class name and have it located under "application/models/Foo.php"
2.- If you want to add other namespaces/libraries to your project you could add these under the library/ folder. In the "My_" namespace case you should add it to "library/My" folder.
Here, you can have a look to the directory structure of a basic Zend Framework project:
|-- application
| |-- Bootstrap.php
| |-- configs
| | `-- application.ini
| |-- controllers
| | |-- ErrorController.php
| | `-- IndexController.php
| |-- models
| `-- views
| |-- helpers
| `-- scripts
| |-- error
| | `-- error.phtml
| `-- index
| `-- index.phtml
|-- library
|-- public
| |-- .htaccess
| `-- index.php
`-- tests
|-- application
| `-- bootstrap.php
|-- library
| `-- bootstrap.php
`-- phpunit.xml
By the way i would recomend you to have a look to the Zend Framework Quick Start guide:
http://framework.zend.com/manual/en/learning.quickstart.html
I initialize my placeholders for my global layout within the Bootstrap.php as described here.
public function _initPlaceholders()
{
$this->bootstrap('View');
$view = $this->getResource('View');
$view->doctype('XHTML11');
$view->headTitle('Foo Bar Title')
->setSeparator(' :: ');
$view->headMeta()->appendHttpEquiv(
'content-type',
'application/xhtml+xml; charset=UTF-8'
);
$view->headMeta()->appendName('robots', 'index,follow');
$view->headLink()->appendStylesheet('/styles/styles.css', 'screen')
->appendStylesheet('/styles/print.css', 'print');
}
The rendered HTML looks correct.
<title>Foo Bar Title</title>
<link href="/styles/styles.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/styles/print.css" media="print" rel="stylesheet" type="text/css" />
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<meta name="robots" content="index,follow" />
But the CSS doesn't get loaded correctly because Zend_Controller thinks it's a controller or something. When I try to open the CSS files the following error occurs:
Fatal error: Uncaught exception
'Zend_Controller_Dispatcher_Exception'
with message 'Invalid controller
specified (error)'
Any hints?
[update]
Ok, just added the following line to my .htaccess file and all works as expected now...
RewriteRule
!.(js|ico|txt|gif|jpg|png|css|htc|swf|htm)$
index.php
A typical Zend project layout looks something like this:
.
|-- application
| |-- Bootstrap.php
| |-- configs
| |-- controllers
| |-- forms
| |-- layouts
| |-- models
| `-- views
|-- library
`-- public
|-- images
| `-- favicon.ico
|-- index.php
|-- js
| `-- scripts.js
`-- styles
`-- style.css
Does yours look similar? Specifically, do you have CSS and JavaScript files somewhere under the public folder (and not the application folder)? If so, can you review file permissions?
Also, I recommend reviewing file permissions. If the CSS files aren't readable by the Apache process, then Apache won't be able to serve them.