powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / PHP, Perl, Python [игнор отключен] [закрыт для гостей] / Kohana+ajax расположение файлов
2 сообщений из 2, страница 1 из 1
Kohana+ajax расположение файлов
    #38920200
Золотов Константин
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Здравствуйте.
Изучаю kohana+jquery.
Структура каталогов такая (веб сервер winginx)
kohana2.ru
-application
--cashe
--classes
---controller
---model
--config
--i18n
--logs
--messages
--views
--bootstraps.php
-modules
-public_html
--css
--js
--index.php
-system

С контроллерами и въюхами разобрался. Контент выводится каскадные таблицы стилей работают. javascripts работают.
Код: html
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kohana 3.3</title>
<link rel="stylesheet" type="text/css" href="css/style.css" media="all" />
<link rel="stylesheet" type="text/css" href="css/jtablethemes/lightcolor/blue/jtable.css" />

<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/jquery.ui.core.js"></script>
<script type="text/javascript" src="js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="js/jquery.ui.button.js"></script>
<script type="text/javascript" src="js/jquery.ui.dialog.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="js/jquery.jtable.js"></script>
<script type="text/javascript" src="js/my_js.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		loadDataJTable();
	});
</script>
</head>
<body>
<div id="wrapper">
        <div class="container">
            <div class="main">
                <?php echo $content; ?>
            </div>
        </div>
    </div>
</div>
</body>
</html>


Грузится контент
Код: html
1.
2.
3.
4.
5.
6.
7.
8.
<div class="navigate">
	<ul class="top-menu">
		<li>
			<div id="btnLoad">Загрузить данные</div>
		</li>
	</ul>
</div>
<div id="tblData"></div>


В loadDataJTable есть функция:
Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
function loadDataJTable() {
	$("#btnLoad").click(function(){
		//Очищаем элемент с id tblData
		$("#tblData").empty();
		$("#tblData").html('<h2>Загрузка данных</h2><br>');
		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: '/data/loaddata', //вот здесь проблема
			data: 'r',
			success: function(response) {
				if (response.code == 'error')
				{
					$("#error").slideDown('slow');
				};
				if (response.code == 'success')
				{
					$("#tblData").load('loaddata');
				};
			}
		});
	});
};


Когда срабатывает событие click на btnLoad, кохана ругается, что http://kohana2.ru/data/loaddata не найдено.
Но я хочу, чтобы data был контроллером, а loaddata функция которая данные возвращает в формате JSON и не хочу выкладывать в каталог public_html.
По пробовал в bootstrap.php настроить роутинг
Код: php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
Route::set('data', 'data(/<action>)') //указывал и action loadddata
	->defaults(array(
		'controller' => 'data',
		'action' => '', //loaddata
	));
	
Route::set('default', '(<controller>(/<action>(/<id>)))')
	->defaults(array(
		'controller' => 'welcome',
		'action'     => 'index',
	));


Но что-то роутинг не работает.
Где я что-то неправильно сделал?
Или я скрипты должен положить внутрь каркаса коханы?
Прошу помощи.
...
Рейтинг: 0 / 0
Kohana+ajax расположение файлов
    #38920292
Золотов Константин
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Да и еще у меня роутинг не работает. по всей видимости
Код: php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
<?php defined('SYSPATH') or die('No direct script access.');

// -- Environment setup --------------------------------------------------------

// Load the core Kohana class
require SYSPATH.'classes/kohana/core'.EXT;

if (is_file(APPPATH.'classes/kohana'.EXT))
{
	// Application extends the core
	require APPPATH.'classes/kohana'.EXT;
}
else
{
	// Load empty core extension
	require SYSPATH.'classes/kohana'.EXT;
}

/**
 * Set the default time zone.
 *
 * @see  http://kohanaframework.org/guide/using.configuration
 * @see  http://php.net/timezones
 */
date_default_timezone_set('Asia/Krasnoyarsk');

/**
 * Set the default locale.
 *
 * @see  http://kohanaframework.org/guide/using.configuration
 * @see  http://php.net/setlocale
 */
setlocale(LC_ALL, 'ru_RU.utf-8');

/**
 * Enable the Kohana auto-loader.
 *
 * @see  http://kohanaframework.org/guide/using.autoloading
 * @see  http://php.net/spl_autoload_register
 */
spl_autoload_register(array('Kohana', 'auto_load'));

/**
 * Enable the Kohana auto-loader for unserialization.
 *
 * @see  http://php.net/spl_autoload_call
 * @see  http://php.net/manual/var.configuration.php#unserialize-callback-func
 */
ini_set('unserialize_callback_func', 'spl_autoload_call');

// -- Configuration and initialization -----------------------------------------

/**
 * Set the default language
 */
I18n::lang('ru-ru');

/**
 * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
 *
 * Note: If you supply an invalid environment name, a PHP warning will be thrown
 * saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>"
 */

Kohana::$environment = Kohana::DEVELOPMENT;

if (isset($_SERVER['KOHANA_ENV']))
{
	Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
}

/**
 * Initialize Kohana, setting the default options.
 *
 * The following options are available:
 *
 * - string   base_url    path, and optionally domain, of your application   NULL
 * - string   index_file  name of your index file, usually "index.php"       index.php
 * - string   charset     internal character set used for input and output   utf-8
 * - string   cache_dir   set the internal cache directory                   APPPATH/cache
 * - boolean  errors      enable or disable error handling                   TRUE
 * - boolean  profile     enable or disable internal profiling               TRUE
 * - boolean  caching     enable or disable internal caching                 FALSE
 */
Kohana::init(array(
	'base_url'   => '/',
        'index_file' => FALSE,
));

/**
 * Attach the file write to logging. Multiple writers are supported.
 */
Kohana::$log->attach(new Log_File(APPPATH.'logs'));

/**
 * Attach a file reader to config. Multiple readers are supported.
 */
Kohana::$config->attach(new Config_File);

/**
 * Enable modules. Modules are referenced by a relative or absolute path.
 */
Kohana::modules(array(
	 'auth'       => MODPATH.'auth',       // Basic authentication
	// 'cache'      => MODPATH.'cache',      // Caching with multiple backends
	// 'codebench'  => MODPATH.'codebench',  // Benchmarking tool
	 'database'   => MODPATH.'database',   // Database access
	// 'image'      => MODPATH.'image',      // Image manipulation
	 'orm'        => MODPATH.'orm',        // Object Relationship Mapping
	// 'unittest'   => MODPATH.'unittest',   // Unit testing
	// 'userguide'  => MODPATH.'userguide',  // User guide and API documentation
	));

/**
 * Set the routes. Each route must have a minimum of a name, a URI and a set of
 * defaults for the URI.
 */
/**Route::set('regions', '<action>', array(
                                    'action' => '(index|view|add|update|delete)'))
	->defaults(array(
		'controller' => 'regions',
	));**/
Route::set('page', 'about')
	->defaults(array(
            'controller' => 'page',
            'action'     => 'about',
	)); 
 
Route::set('page', 'contacts')
	->defaults(array(
            'controller' => 'page',
            'action'     => 'contacts',
	));

Route::set('default', '(<controller>(/<action>(/<id>)))')
	->defaults(array(
		'controller' => 'start',
		'action'     => 'index',
	));


Контроллер page
Код: php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Page extends Controller_Base {

    public function action_about()
	{
		$this->template->content = View::factory('/about');
	}
    public function action_contact()
        {
            $this->template->content = View::factory('/contact');
        }

} // End Regions


View about and contact
Код: php
1.
2.
3.
<h3>Про это</h3>

<h3>Контакты</h3>


Главная вьюшка
Код: php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kohana 3.3</title>
<link rel="stylesheet" type="text/css" href="css/style.css" media="all" />

<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
</head>
<body>
<div id="wrapper">
    <div class="main">
        <div class="header">
            Заголовок
        </div>
        <div class="navigate">
            <div class="top_menu">
                <ul id="list_menu_top">
                    <li>
                        <div><a href="<?php echo URL::site('regions/view'); ?>"> Регионы</a></div>
                    </li>
                    <li>
                        <div>Станции</div>
                    </li>
                    <li>
                        <a href="<?php echo URL::site('page/about'); ?>">Про . . . </a>
                    </li><li>
                        <a href="<?php echo URL::site('page/contact'); ?>">Контакты</a>
                    </li>
                </ul>
             </div>
        </div>
        <div class="data">
            Дата<br>
            <?php $content; ?>
            Директория  - <?php echo Request::current()->directory(); ?>


            Контроллер - <?php echo Request::current()->controller(); ?>


            Метод - <?php echo Request::current()->action(); ?>
        </div>
        <div class="footer">
            Подвал
        </div>
     </div>
</div>
</body>
</html>
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / PHP, Perl, Python [игнор отключен] [закрыт для гостей] / Kohana+ajax расположение файлов
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]